Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

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.inDispatch

Five behaviours, each pinned by a test in the package:

  1. Outside a dispatch, perform is immediate and returns the host's result.
  2. Inside a dispatch, Cmds are recorded and drained after the action, in order. perform returns { ok: true, value: Promise }; the promise settles when the Cmd is performed.
  3. A nested dispatch keeps the outer list. Only the outermost drains.
  4. 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.
  5. A refusal is said through warn: [cmd] not performed: <error>. The log gate refuses a run that contains one.