The core namespace providing the public API



Atom keeping track of defined states (by namespaced
keywords) internally. Declared public and dynamic here, as an
extension point to influence which states are started or stopped.
Do not fiddle with the root binding.



Can be bound to a map with vars as keys and State records as
values. The :start and :stop expressions of the State value will
be used when the corresponding var key is started. The
`with-substitutes` macro offers a nicer syntax.



(defstate name & args)
Define a state. At least a :start expression should be supplied.
Optionally one can define a :stop expression. Supports docstring and
attribute map.


(start)(start up-to-var)
Start all the loaded defstates, or only the defstates up to the
given state var. Only stopped defstates are started. They are
started in the context of the current session.



(state & {:keys [start stop name], :or {name "-anonymous-"}, :as fields})
Create an anonymous state, useful for substituting. Supports three
keyword arguments. A required :start expression, an optional :stop
expression, and an optional :name for the state.


Retrieve status map for all states.


(stop)(stop down-to-var)
Stop all the loaded defstates, or only the defstates down to the
given state var. Only started defstates are stopped. They are
stopped in the context of the current session.



(with-session & body)
Creates a new thread, with a new system of states. All states are
initially in the stopped status in this thread, regardless of the
status in the thread that spawns this new session. This spawned
thread and its subthreads will automatically use the states that are
started within this thread or subthreads. Exiting the spawned thread
will automatically stop all states in this session.

Returns a map with the spawned :thread and a :promise that will be
set to the result of the body or an exception.



(with-substitutes var-sub-pairs & body)
Given a vector with var-state pairs, an inner start function will
use the :start expression of the substitutes for the specified
vars. Nested `with-substitutes` are merged.