@@ -32,15 +32,6 @@ def __init__(self):
3232 self .nexus_client = workflow .create_nexus_client (
3333 service = MyNexusService ,
3434 endpoint = NEXUS_ENDPOINT ,
35- # Set the cancellation type to WAIT_REQUESTED. This means that the caller
36- # will wait for the cancellation request to be received by the handler before
37- # proceeding with the cancellation.
38- #
39- # By default, the caller would wait until the operation is completed.
40- operation_options = workflow .NexusOperationOptions (
41- schedule_to_close_timeout = timedelta (seconds = 10 ),
42- cancellation_type = workflow .NexusOperationCancellationType .WAIT_REQUESTED ,
43- ),
4435 )
4536
4637 @workflow .run
@@ -58,19 +49,30 @@ async def run(self, message: str) -> str:
5849 names = ["Nexus-1" , "Nexus-2" , "Nexus-3" , "Nexus-4" , "Nexus-5" ]
5950
6051 # Create a list to store operation tasks
61- tasks = []
52+ tasks : list [asyncio .Task [MyOutput ]] = []
53+
54+ async def await_operation_result (
55+ op_handle : workflow .NexusOperationHandle [MyOutput ],
56+ ) -> MyOutput :
57+ return await op_handle
6258
6359 # Create our cancellation scope. Within this scope we call the nexus operation
6460 # asynchronously for each name.
6561 async def start_operations ():
6662 for name in names :
6763 # Start each operation asynchronously
64+ # Set the cancellation type to WAIT_REQUESTED. This means that the
65+ # caller will wait for the cancellation request to be received by the
66+ # handler before proceeding with the cancellation.
67+ # By default, the caller would wait until the operation is completed.
6868 handle = await self .nexus_client .start_operation (
6969 MyNexusService .my_workflow_run_operation ,
7070 MyInput (name ),
71+ schedule_to_close_timeout = timedelta (seconds = 10 ),
72+ cancellation_type = workflow .NexusOperationCancellationType .WAIT_REQUESTED ,
7173 )
7274 # Create a task that waits for the operation result
73- tasks .append (asyncio .create_task (handle ))
75+ tasks .append (asyncio .create_task (await_operation_result ( handle ) ))
7476
7577 # Execute all nexus operations within a try block so we can cancel them
7678 try :
0 commit comments