Flows-102
Anatomy of a Flow
We haven’t covered the standard library yet, but for now, here are the basics: std
is a globally available
module, there to help you interact with the runtime.
You create flows using std.flow
. It takes two parameters:
- Name of the flow
- An instance of a class
std.flow
lets you go through the looking glass. It lets you provide a new state machine to the runtime, such that
when it ticks, it manages this newly given state machine as well.
FlowExecutor
A standard flow, lazily evaluated.
When you don’t provide a schedule to std.flow
and call a FlowFunction
, you get a FlowExecutor
. This is a handle that encapsulates work.
A FlowExecutor
doesn’t start its work unless explcitly told to do so. It has two function through which
you can start execution:
await
in next section.RT
captures the return type of the FlowFunction that spawned it, M
we can ignore for now.
Given a FlowExecutor
is a handle, we can do this:
Try this code in the playground to see what happens!
Scheduled Flows
A scheduled flow, eagerly evaluated, run immediately.
You can provide a schedule to std.flow
to get a ScheduledFlow
. A schedule
is an object and it can
have of the following keys:
Start the flow after given number of ticks
have passed.
Start a flow every time given number of ticks
pass.
A ScheduledFlow
is evaluated immediately, and it begins its work in the same tick it’s created.
Check out the playground to see how we can emulate a polling job using it.