Hello @nareshbhatia
Looking at the TypeScript examples, workflows are returning unstructured message strings, usually returned by activities.
You can return any type of object it has to be serializable. please see:
- https://github.com/temporalio/samples-typescript/blob/main/ejson/src/client.ts#L32
- Passing functions from activities to workflows - #3 by bergundy
- What are the best practices around determining the return value from a workflow?
I think this is closely related to your business. What do you need your workflow function to return?
- Would it be a good pattern to at least return the current workflow state so that the client can enable the next set of valid actions. Currently my client is using
await workflow.query('workflowState')
to get the current state, but that seems like an unnecessary round trip. Of course, I realize that the workflow state can change anytime, but this approach might cover some use cases without a round trip.
To get the internal workflow state the recommendation is to use queries for running workflows. Build durable applications with Temporal | Temporal Documentation, and as you have mentioned you can return it as part of the workflow result.
- How does the client access the return value (in TypeScript)?
const result: Result = await handle.result()
Have a look at this example https://github.com/temporalio/samples-typescript/blob/main/ejson/src/client.ts#L32
Just in case it helps, with handle.describe()
you can get other useful information, like the workflow status (completed, running…) : await handle.describe()).status
Antonio