@@ -50,6 +50,7 @@ class OpDefinitionType(IntEnum):
50
50
@dataclass
51
51
class SyncResponse :
52
52
op_definition_type : OpDefinitionType
53
+ use_async_def : bool
53
54
54
55
55
56
@dataclass
@@ -86,6 +87,7 @@ class OpOutput:
86
87
class ServiceInterface :
87
88
sync_or_async_operation : nexusrpc .interface .Operation [OpInput , OpOutput ]
88
89
sync_operation : nexusrpc .interface .Operation [OpInput , OpOutput ]
90
+ non_async_sync_operation : nexusrpc .interface .Operation [OpInput , OpOutput ]
89
91
async_operation : nexusrpc .interface .Operation [OpInput , OpOutput ]
90
92
91
93
@@ -176,6 +178,16 @@ async def sync_operation(
176
178
start_options_received_by_handler = options ,
177
179
)
178
180
181
+ @nexusrpc .handler .sync_operation
182
+ def non_async_sync_operation (
183
+ self , input : OpInput , options : nexusrpc .handler .StartOperationOptions
184
+ ) -> OpOutput :
185
+ assert isinstance (input .response_type , SyncResponse )
186
+ return OpOutput (
187
+ value = "sync response" ,
188
+ start_options_received_by_handler = options ,
189
+ )
190
+
179
191
@temporalio .nexus .handler .workflow_run_operation
180
192
async def async_operation (
181
193
self , input : OpInput , options : nexusrpc .handler .StartOperationOptions
@@ -276,48 +288,73 @@ def _get_operation(
276
288
SyncResponse ,
277
289
OpDefinitionType .SHORTHAND ,
278
290
CallerReference .IMPL_WITH_INTERFACE ,
291
+ True ,
279
292
): ServiceImpl .sync_operation ,
280
293
(
281
294
SyncResponse ,
282
295
OpDefinitionType .SHORTHAND ,
283
296
CallerReference .INTERFACE ,
297
+ True ,
284
298
): ServiceInterface .sync_operation ,
299
+ (
300
+ SyncResponse ,
301
+ OpDefinitionType .SHORTHAND ,
302
+ CallerReference .IMPL_WITH_INTERFACE ,
303
+ False ,
304
+ ): ServiceImpl .non_async_sync_operation ,
305
+ (
306
+ SyncResponse ,
307
+ OpDefinitionType .SHORTHAND ,
308
+ CallerReference .INTERFACE ,
309
+ False ,
310
+ ): ServiceInterface .non_async_sync_operation ,
285
311
(
286
312
SyncResponse ,
287
313
OpDefinitionType .LONGHAND ,
288
314
CallerReference .IMPL_WITH_INTERFACE ,
315
+ True ,
289
316
): ServiceImpl .sync_or_async_operation ,
290
317
(
291
318
SyncResponse ,
292
319
OpDefinitionType .LONGHAND ,
293
320
CallerReference .INTERFACE ,
321
+ True ,
294
322
): ServiceInterface .sync_or_async_operation ,
295
323
(
296
324
AsyncResponse ,
297
325
OpDefinitionType .SHORTHAND ,
298
326
CallerReference .IMPL_WITH_INTERFACE ,
327
+ True ,
299
328
): ServiceImpl .async_operation ,
300
329
(
301
330
AsyncResponse ,
302
331
OpDefinitionType .SHORTHAND ,
303
332
CallerReference .INTERFACE ,
333
+ True ,
304
334
): ServiceInterface .async_operation ,
305
335
(
306
336
AsyncResponse ,
307
337
OpDefinitionType .LONGHAND ,
308
338
CallerReference .IMPL_WITH_INTERFACE ,
339
+ True ,
309
340
): ServiceImpl .sync_or_async_operation ,
310
341
(
311
342
AsyncResponse ,
312
343
OpDefinitionType .LONGHAND ,
313
344
CallerReference .INTERFACE ,
345
+ True ,
314
346
): ServiceInterface .sync_or_async_operation ,
315
347
}[
316
348
{True : SyncResponse , False : AsyncResponse }[
317
349
isinstance (op_input .response_type , SyncResponse )
318
350
],
319
351
op_input .response_type .op_definition_type ,
320
352
op_input .caller_reference ,
353
+ (
354
+ op_input .response_type .use_async_def
355
+ if isinstance (op_input .response_type , SyncResponse )
356
+ else True
357
+ ),
321
358
]
322
359
323
360
@@ -400,7 +437,7 @@ async def test_sync_response(
400
437
args = [
401
438
CallerWfInput (
402
439
op_input = OpInput (
403
- response_type = SyncResponse (op_definition_type ),
440
+ response_type = SyncResponse (op_definition_type , True ),
404
441
start_options = nexusrpc .handler .StartOperationOptions (
405
442
headers = {"header-key" : "header-value" },
406
443
),
@@ -579,7 +616,7 @@ async def test_untyped_caller(
579
616
args = [
580
617
CallerWfInput (
581
618
op_input = OpInput (
582
- response_type = SyncResponse (op_definition_type ),
619
+ response_type = SyncResponse (op_definition_type , True ),
583
620
start_options = nexusrpc .handler .StartOperationOptions (),
584
621
caller_reference = caller_reference ,
585
622
),
0 commit comments