Skip to content

Glossary ​

The terms of @sekhmet/dispatch's ubiquitous language, each named the way the code names it. The concepts guide explains how they fit together. Terms Sekhmet's packages share, such as Option, Poll, Vow, Panic, panic boundary, double fault, and main and mini, live in the root glossary and aren't redefined here.

The two capabilities ​

  • Dispatch (controller.dispatch(value)): the one-shot event that carries a typed value, like an AbortSignal's abort with a T instead of reason: any. The call returns the value already there, like Rust's HashMap::insert: a main None if this call dispatched, Some(first) if an earlier one had. Losing the race isn't an error.
  • Dispatch controller (DispatchController<T>): the write side, like AbortController. Holding it is the right to dispatch. It is built with a panic boundary ({ panics }), inside which its listeners run.
  • Dispatch signal (DispatchSignal<T>): the read side, like AbortSignal. Holding it is the right to hear the dispatch: listen to it, poll it, derive from it and convert it, but never dispatch it. It has no public constructor, and is covariant in T.
  • First dispatch wins: the rule that a dispatch happens once. A later dispatch, including one made by a listener mid-dispatch, changes nothing and returns the first value.

Reading a signal ​

  • Poll (signal.poll()): reads a signal without waiting, as a main Poll: Ready(value) once dispatched, Pending before.
  • Listener (Listener<T>): a synchronous function a dispatch runs once with its value. It returns undefined, so an async listener is a compile error.
  • When dispatched (signal.whenDispatched(listener)): runs the listener when the signal dispatches, or at once if it already has, and returns an Unsubscribe. Listeners run in the order they were added, and one added mid-dispatch joins the end of the queue.
  • Late listener: a listener added after the dispatch. It runs at once, where an AbortSignal listener added after the abort never fires.
  • Unsubscribe (Unsubscribe): removes a listener that hasn't run yet, reporting true the first time it removed one and false once the listener has run or been removed.
  • Throwing listener: a listener with a bug. The controller runs it inside its panic boundary's catchUnwind, so the throw is reported to the runtime's hook, the other listeners still run, and dispatch returns normally. Only a double fault reaches the caller, after the dispatch completes.

Derived signals ​

  • Derived signal: a signal built from others by map, zip, DispatchSignal.any or DispatchSignal.fromAbortSignal. It holds no listeners of its own: it forwards each listener to its sources and reads them when polled, so one nobody listens to holds no subscription.
  • Root boundary: the panic boundary of the controller whose dispatch runs a derived signal's listener. A derived signal needs no runtime of its own.
  • Map (signal.map(mapping)): a signal of mapping(value). It remembers the mapped value, so the mapping runs once however many listeners and polls read it.
  • Poisoning: what a throwing mapping does to its mapped signal, like Rust's LazyLock. The throw goes to whoever ran the mapping first, and every later read panics with a poison panic.
  • Poison panic (Panic (Poisoned)): the panic a read of a poisoned signal throws or reports, whose cause is the mapping's original throw. Each reader gets its own.
  • Zip (signal.zip(other)): a signal of both values as a pair, once both have dispatched. It holds only its first source until that one fires, then only its second.
  • Any (DispatchSignal.any(signals)): a signal of the first value dispatched among its sources. It decides the first time it sees a dispatch, picking the earliest source in the array that is Ready then. any([]) never dispatches.
  • Dispatched (DispatchSignal.dispatched({ value })): a signal already dispatched with value, with no controller. Its listeners run in the caller's call, so a throw propagates to that caller.
  • Never (DispatchSignal.never()): a signal that never dispatches, with no controller.

Bridges ​

  • Wait (signal.wait()): the value as a Promise, subscribed until the dispatch.
  • To vow (signal.toVow()): the value as a new main Vow on each call, resolved inside the dispatch with no microtask in between.
  • To abort signal (signal.toAbortSignal()): an AbortSignal that aborts with the dispatched value as its reason, for fetch and other platform APIs. It aborts at once for a signal that has already dispatched.
  • From abort signal (DispatchSignal.fromAbortSignal({ signal, panics })): a derived signal of an AbortSignal's abort reason, typed unknown. It adds a platform listener only while it has listeners, and runs them inside panics.