transition as a core.async flow: the same steps and invokes, without the
loop. Two procs in a cycle — :machine runs step/step (pure), :invoke runs
invoke/invoke-event (the side effect) — so a slow :src blocks no caller.
Messages carry the ctx (the procs keep none), so one flow serves any number of machine instances. One channel in, one out:
in [:machine :events] {:ctx :event …} sent with flow/inject out :out {:ctx :event :entered :done? …} one per microstep
Any other key of a message (an :id, a reply promise, a trace context) rides along, through the invoke and back, onto every message out.
With {:async? true} in the opts every microstep comes out, the last with
:done? true; without it only that last one, the ctx transition would return.
A step that throws, or a :src that throws something other than an ex-info
(an ex-info is its :on-error), ends it: the last message carries the :error.
Inside, [:machine :to-invoke] → [:invoke :from-machine] carries an invoke to
run, and [:invoke :to-machine] → [:machine :from-invoke] the event it raised.
The :invoke proc runs each :src through its :around-invoke, if given:
(fn [msg run] … (run) …), to set up a trace context, say.
Send the next event for an instance only after its :done? message: otherwise it steps from an older ctx. Needs org.clojure/core.async with flow (an optional dependency).
`transition` as a core.async flow: the same steps and invokes, without the
loop. Two procs in a cycle — :machine runs `step/step` (pure), :invoke runs
`invoke/invoke-event` (the side effect) — so a slow :src blocks no caller.
Messages carry the ctx (the procs keep none), so one flow serves any number
of machine instances. One channel in, one out:
in [:machine :events] {:ctx :event …} sent with flow/inject
out :out {:ctx :event :entered :done? …} one per microstep
Any other key of a message (an :id, a reply promise, a trace context) rides
along, through the invoke and back, onto every message out.
With {:async? true} in the opts every microstep comes out, the last with
:done? true; without it only that last one, the ctx `transition` would return.
A step that throws, or a :src that throws something other than an ex-info
(an ex-info is its :on-error), ends it: the last message carries the :error.
Inside, [:machine :to-invoke] → [:invoke :from-machine] carries an invoke to
run, and [:invoke :to-machine] → [:machine :from-invoke] the event it raised.
The :invoke proc runs each :src through its :around-invoke, if given:
`(fn [msg run] … (run) …)`, to set up a trace context, say.
Send the next event for an instance only after its :done? message: otherwise
it steps from an older ctx. Needs org.clojure/core.async with flow (an
optional dependency).(invoke-transform
{:keys [opts around-invoke] :or {around-invoke run-directly} :as proc-state}
_in
{:keys [ctx invoke] :as msg})Runs the invoke on the ctx without the state key, as transition does,
through :around-invoke when there is one, and sends the message back to the
machine with the event it raised in place of the invoke. A :src that throws
something other than an ex-info sends it back with the :error instead.
Runs the invoke on the ctx without the state key, as `transition` does, through :around-invoke when there is one, and sends the message back to the machine with the event it raised in place of the invoke. A :src that throws something other than an ex-info sends it back with the :error instead.
(machine-flow machine {:keys [opts out-ch around-invoke]})A flow config (for flow/create-flow) running machine: events injected at
[:machine :events] as {:ctx :event …}, steps out on out-ch — every one
with {:async? true} in opts, else only the last (:done? true). Each :src runs
through around-invoke when given. Keep out-ch drained: the machine waits
on a full channel.
A flow config (for `flow/create-flow`) running `machine`: events injected at
[:machine :events] as `{:ctx :event …}`, steps out on `out-ch` — every one
with {:async? true} in `opts`, else only the last (:done? true). Each :src runs
through `around-invoke` when given. Keep `out-ch` drained: the machine waits
on a full channel.(machine-transform {:keys [machine opts] :as proc-state}
_in
{:keys [ctx event error] :as msg})One microstep for msg ({:ctx :event …}). Entering a state with an :invoke
sends it on :to-invoke; otherwise the step is the last, :done?. The step goes
to :out when it is the last, or for every step when the opts say :async?.
A message that carries an :error (from the invoke), or a step that throws,
goes out as the last, with the :error. Every other key of msg is kept.
One microstep for `msg` ({:ctx :event …}). Entering a state with an :invoke
sends it on :to-invoke; otherwise the step is the last, :done?. The step goes
to :out when it is the last, or for every step when the opts say :async?.
A message that carries an :error (from the invoke), or a step that throws,
goes out as the last, with the :error. Every other key of `msg` is kept.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |