Anatomy of a Flow
std
is a globally available
module, there to help you interact with the runtime.
You create flows using std.flow
. It takes two parameters:
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.
A standard flow, lazily evaluated.
What's a FlowGenerator?
std.flow
returns a FlowGenerator
, which is an object that closely resembles the class instance that you provided.
With one key difference, it still has methods, but all of them are FlowFunction
s.What's a FlowFunction?
FlowFunction
represents a factory that
can produce one.It returns a ScheduledFlow
if a schedule is provided to std.flow
, or a FlowExecutor
if not.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:
A scheduled flow, eagerly evaluated, run immediately.
std.flow
to get a ScheduledFlow
. A schedule
is an object and it can
have of the following keys:
ticks
have passed.ticks
pass.ScheduledFlow
is evaluated immediately, and it begins its work in the same tick it’s created.