/** * The core loop both engines run (#280, spike #264). It does five things and * nothing else: it keeps one serial tail, folds a Msg into a transition, saves * before any effect, reconciles the running Subs, and runs the transition's * Cmds, dispatching what they return. It has no special case for any built-in. * * One loop, not one per engine (#283). The loop calls a handler and a runner * through erased signatures and awaits a Promise either way, so an engine's * own types never pass through it. The Effect engine turns each handler and * runner into a fiber at its own edge, run with the services the caller * provided, so Effect services (`R`) reach every handler without the loop * carrying a type slot for them — the gap spike #260's generic loop left open. * Sharing the loop is also what makes the two engines' traces identical: the * fold, the save order and the built-ins are the same code. * * Everything else `run` offers is an {@link Extension} built on eleven points: * * 1. `update` — middleware over the fold. Returning `null` means "no * transition": no save, no effects, no commit. * 2. `interpret` — middleware over one Cmd's handler call; it maps what the * handler returned to the Msgs to dispatch, if any. * 3. `store` — a wrapper over the store the caller handed `run`. * 4. `installed` — called once a transition's State is past its save and its * Subs are reconciled, before its first Cmd's handler starts. * This is Elm's `view`: it never waits on a Cmd (#695). * 5. `commit` — called after a transition's effects, with the Msg and the * committed State, even when a Cmd handler threw. Boot * passes `undefined` for the Msg. * 6. `saveFailed` — called when a transition's save rejects, before that * rejection reaches the dispatch caller. * 7. `subFailed` — called when a Sub's failure stops the run, before the * engine is told to stop it. * 8. `halted` — called when an extension halts the run with an error. * 9. `drained` — called once no Msg can fold any more, so the State is the * run's last: `stop()` has finished with the queue, the * host's or the one a failure started. * 10. `ctx` — keys added to the ctx every Cmd handler receives, so a * handler that runs another handler inside its own can reach * the same machinery the loop applies to it. * 11. `answer` — parse a later answer against its persisted Cmd, before * durable admission; the Cmd boundary owns this rule. * * An extension may also add methods to the run handle (`handle`). Array order * is nesting order: the first extension's middleware is the outermost, and * `installed` and commit callbacks run first to last. `builtinExtensions` * (`./builtins`) fixes that order for every engine; it is not a user-facing * plugin API (#268). * * `stop()` is the core's own lifecycle, because the gate it drives is what every * dispatch passes through: open → draining → closed, or → abandoned when * `stop()` gives up on the queue (ADR 0025), never backwards. */ declare const post: unique symbol; /** * What `tell` answers, at once, about the Msg it was handed. It says where the * Msg stands at that moment and nothing about how it ends. * * - `"queued"`: the Msg is on the receiver's line. It has not been handled. * - `"stopped"`: the receiver is stopping or has stopped, so the Msg is not on * its line and never will be. * - `"no_cell"`: the receiver's current State has no cell for the Msg, so the * Msg is not on its line. That reads the State as it is now, not the State * the Msgs already in line will leave. */ type TellAnswer = "queued" | "stopped" | "no_cell"; /** A run handle `tell` can reach the line of. */ interface Postable { readonly [post]: (msg: M, takes: (state: S) => boolean) => TellAnswer; } export type { Postable as P, TellAnswer as T };