Green - Tasks (it might have an API call, function call, or webhook)
Yellow - Wait state
In this diagram, the red color marked portion needs to be executed parallelly but among that we need path1, Path2, and Path3 to be executed in linear fashion.
T2 has to start its execution after 9 states are completed. So it has to wait for all 3 paths to complete.
Question 1) Is it possible to put wait ( Workflow.sleep(some duration) ) for 3 states at a time?
I can achieve parallel execution using Async, but using .get on the promise object will block my thread.
Question 2) Is it possible to achieve without blocking?
I tried using thenApply,handle on the promise objects but my workflow code has completed without executing this thenAppy and handle callbacks.
Question 1) Is it possible to put wait ( Workflow.sleep(some duration) ) for 3 states at a time?
I can achieve parallel execution using Async, but using .get on the promise object will block my thread.
Yes, you can use Async to start three threads and use Workflow.sleep in each of them. Then you use Promise.allOf on the Promises returned by the Async.<…> function to join the threads.
Question 2) Is it possible to achieve without blocking?
Yes, you can implement these branches asynchronously. You still have to block the main workflow thread as fully asynchronous workflow implementation is not supported yet.
I hope using Promise.allOf(promiseList).get(); and Promise.allOf(promiseList); makes no difference. Correct me if i am wrong
So as you said, in this way main workflow thread will be blocked until it completes all its promises as full asynchronous workflow implementation is not supported yet.
The reason that it worked was that you didn’t need Promise.allOf in your case at all, as the following loop called get on every Promise anyway. So NOOP was fine :).
It is either waits for all threads to complete or it waits for any of the threads to complete. (allOf, anyOf)
If you see the diagram,
I will be calling all the three tasks parallelly using Async which are,
Path1-T1
Path2-T1
Path3-T1
Say, if Path1-T1 takes 2 mins and Path2-T1 and Path3-T1 take just 3 sec to complete.
My case is after completing Path2-T1 it should call Path2Wait (5 min) and after completing Path3-T1 it should call Path3-T2.
if I use allOf then all my threads will wait for each other to complete.
If I use anyOf then my first completed thread returning its result and workflow cmpleted
If I use normal loop .get() on the promise object then the first promise.get() will block before others to continue.
As soon as the main workflow method (annotated with @WorkflowMethod) returns workflow completes. So make sure that you block the main workflow thread until all the work of the workflow is done.