Convention based lifecycle management of asynchronous chains. This implements a lightweight take on the ideas behind interceptors and similar libraries.
Notable differences are:
Convention based lifecycle management of asynchronous chains. This implements a lightweight take on the ideas behind interceptors and similar libraries. Notable differences are: - Manifold is the sole provided execution model for chains - No chain manipulation can occur - Guards and finalizer for steps are optional - Exceptions during lifecycle steps stop the execution
(prepare-stage stage opts steps)
Prepare a single stage, discard steps which do not have a handler for a specific stage.
Prepare a single stage, discard steps which do not have a handler for a specific stage.
(run init steps)
(run init opts steps)
Run a series of potentially asynchronous steps in sequence
on an initial value (init
0, threading each step's result to
the next step as input.
Steps are maps or the following keys:
[:id :enter :leave :in :out :discard? :guard]
id
is the unique ID for a stepenter
is the function of the previous result in the enter stageleave
is the function of the previous result in the leave stagein
when present determines which path in the context will
be fed to the handler. The handler is considered a function
of the contexout
when present determines which path in the context to
associate the result to, otherwise replaces the full contextdiscard?
when present, runs the handler but pass the context
untouched to the next stepguard
is an optional predicate of the current context and previous
preventing execution of the step when yielding falseIn the three-arity version, an extra options maps can be provided, with the following keys:
[:augment :executor :initialize :stages :stop-on]
augment
is a function called on the context for each step,
expected to yield an updated context. This can useful to
perform timing tasksexecutor
a manifold executor to execute deferreds oninitialize
is a function called on the context before
running the lifecycle.stages
a list of stages to run through, defaults to
:enter
and :leave
. Every second stage is run in reverse
order.stop-on
predicate which determines whether an early stop is
mandated, for compatibility with interceptors terminate-when
is synonymous.Run a series of potentially asynchronous steps in sequence on an initial value (`init`0, threading each step's result to the next step as input. Steps are maps or the following keys: [:id :enter :leave :in :out :discard? :guard] - `id` is the unique ID for a step - `enter` is the function of the previous result in the enter stage - `leave` is the function of the previous result in the leave stage - `in` when present determines which path in the context will be fed to the handler. The handler is considered a function of the contex - `out` when present determines which path in the context to associate the result to, otherwise replaces the full context - `discard?` when present, runs the handler but pass the context untouched to the next step - `guard` is an optional predicate of the current context and previous preventing execution of the step when yielding false In the three-arity version, an extra options maps can be provided, with the following keys: [:augment :executor :initialize :stages :stop-on] - `augment` is a function called on the context for each step, expected to yield an updated context. This can useful to perform timing tasks - `executor` a manifold executor to execute deferreds on - `initialize` is a function called on the context before running the lifecycle. - `stages` a list of stages to run through, defaults to `:enter` and `:leave`. Every second stage is run in reverse order. - `stop-on` predicate which determines whether an early stop is mandated, for compatibility with interceptors `terminate-when` is synonymous.
(step enter)
(step id handlers & {:as params})
Convenience function to build a step map. Requires and ID and handler, and can be fed additional options
Convenience function to build a step map. Requires and ID and handler, and can be fed additional options
(step* id handlers {:keys [in out lens guard discard?]})
Convenience function to build a step map. Requires and ID and handler, and can be fed additional options
Convenience function to build a step map. Requires and ID and handler, and can be fed additional options
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close