Dispatcher
import { createDispatcher } from '@enc-protocol/cvn'
const d = createDispatcher({ runAction, performNow, warn })
d.dispatch(path, value) // runs the action; drains its Cmds afterwards
d.perform(cmd) // records inside a dispatch; performs now outside
d.inDispatchFive behaviours, each pinned by a test in the package:
- Outside a dispatch,
performis immediate and returns the host's result. - Inside a dispatch, Cmds are recorded and drained after the action, in order.
performreturns{ ok: true, value: Promise }; the promise settles when the Cmd is performed. - A nested dispatch keeps the outer list. Only the outermost drains.
- An unroutable Cmd settles to
{ error }— the same shape as an adapter's own failure, so callers branch the same way whether the adapter refused or the routing did. - A refusal is said through
warn:[cmd] not performed: <error>. The log gate refuses a run that contains one.