Awaiting Flows
A FlowExecutor
has await(): RT
to enable the parent flow to await its result.
Here’s an example:
The line const result = flow.await();
will make the currently executing flow suspend until the awaited flow
is complete.
If you await a flow, it will count as calling that method(FlowFunction
) and hence an edge would be rendered.
Try playing with run()
and await()
and see how the playground changes!
Awaiting multiple flows
In real systems, you are often awaiting multiple things simultaneously, or racing them together.
That’s exactly why we have std.awaitAll()
and std.awaitRace()
.
std.awaitAll
This is the equivalent of JavaScript’s Promise.all. It takes an array of FlowExecutor
and returns an array
corresponding to results of given FlowExecutor
s. For example:
std.awaitRace
This is the equivalent of JavaScript’s Promise.race.
It also takes an array of FlowExecutor
but returns a single value corresponding to the flow which completed first. If a flow wins the race, the remaining flows are cancelled.
For example:
Here’s how it looks like in action:
You can play with the code here.
We have one last mechanism left, events. The tried and tested method for asynchronousity. Let’s cover that in next section!