Promise.get() vs Workflow.await() what are the major differences, and is there a performance benefit associated with one over the other

We have a use case where I have a parent Workflow and there is a child workflow that creates a task that requires human approval to get completed.

Approval endpoints complete the task in which interns complete the child workflow and it also calls a signal method of parent use case which updates the flag isCompleted to true.

To implement this use case, we have two options:

  1. Execute the child workflow asynchronously and use Workflow.await(() → isCompleted) in the parent workflow method, which will block the workflow thread until isCompleted is true.

  2. Execute the child workflow asynchronously and use Promise.get() to wait until the child workflow execution is completed.

Both approaches can fulfill our functional requirements.

Now I wanted yours recommendation on which approach I should go ahead with. Is there any performance advantage of one approach over other, or any guideline like where should I use Workflow.await and where to use Promise.get().

Thanks

Does the child workflow do anything else in addition to creating the task?
If it doesn’t is there a reason to not invoke activity directly from workflow code?

One idea would be to have an activity that creates the task (would have short StartToClose timeout) and then in workflow code wait approval signal via workflow.await.

Your workers can evict executions that are currently awaiting condition evaluation, or are blocked on workflow.sleep for example in order to allow other executions to make progress. So waiting via workflow.await does not technically use your worker resources.

@tihomir thanks for the quick reply.

The main question here is not what is the best solution for this particular use case but rather whether there is any performance advantage of using one over the other. or both of them are complementary and based on the use case we can use either of the ones?

Hi Tiho,

Yes there are a set of activities we want to execute for every Human Task creation and management of its state. And hence its modelled as a workflow instead of an activity.
Like Vikas has replied, the main understanding we are trying to seek is a comparision of Workflow.await on a variable vs Promise.get of the child workflow completion by the parent. Comparision in terms of internal implementation within temporal, performance implications of one over the other, any specific use cases where one can be prefered over the other.

Thanks.

From worker perspective there shouldn’t be a difference, so it’s really up to you if you want to notify parent from child workflow via signal or wait for child workflow completion in parent.

Waiting on child execution promise imho would be easier to implement if the use case is that child workflow completion unblocks parent to continue processing rest of your workflow code.
If the use case is that parent workflow can be unblocked and continue processing on partial human task decisions in child, then would use signal and workflow.await.

1 Like