Using suspend and resume to wait for async results
Some APIs return an async_result_id
. While this is useful if you want to continue the workflow while it is running, sometimes you want to wait for the operation to complete. This is where the suspend_fn
method comes in.
To suspend a workflow, you can use the ctx.suspend_fn
method within a Step
function. This will suspend the workflow until a resume event is received.
The standard way to trigger a resume event when a async_result_id
is ready is to use the resume_when_complete
method.
Note that the same function (reasoning_sync
) will be called when the workflow is resumed, and the resume data will be passed via the ctx.resume_data
property (in this case, the result from the async_result_id
).