stop¶
Source: src/stop.ts
The stop switch of a live run: everything at once, or one subagent of it.
A workflow already honours a signal - that is how a whole run is called
off. What it has no way of expressing is this branch, not the others: the
signal is shared by every subagent under it, and a combinator hands out no
handles. So the switch sits where the handles pass: it wraps spawn, keeps
what came out of it by id, and hands the workflow the signal it will obey.
Both halves are ports, not globals: a script builds one, gives its signal
and its spawn to the workflow, and stops whatever it likes from outside.
The extension is the first caller, not the only possible one.
stopSwitch¶
function
export function stopSwitch(options: StopSwitchOptions = {}): StopSwitch { /* … */ }
Builds the stop switch for one run.
Stopping is one-way: a stopped subagent stays stopped, and a stopped run refuses the turns the workflow has not started yet. Nothing here closes anything - whoever opened a subagent still closes it, on this path like on any other, which is what keeps an interrupted run exportable.
StopSwitch¶
type
export type StopSwitch = {
/**
* Give this to the workflow as its `signal`.
*
* It aborts when {@link StopSwitch.all} is called, and when the outer signal
* does.
*/
readonly signal: AbortSignal;
/**
* Give this to the workflow as its `spawn`.
*
* The subagents it produces are registered on the way out, which is what
* makes {@link StopSwitch.one} possible at all. Delegated children arrive
* here too, as long as the workflow passes the same `spawn` down.
*/
readonly spawn: SpawnFn;
/** Stops one subagent. `false` when no subagent of that id came through here. */
one(id: string): boolean;
/** Stops the run: the turns in flight, and the ones it was about to start. */
all(): void;
};
A live run’s two halves: what it obeys, and what stops it.
StopSwitchOptions¶
type
export type StopSwitchOptions = {
/** An outer signal. Aborting it stops the run, exactly as {@link StopSwitch.all} does. */
signal?: AbortSignal;
/** The `spawn` to wrap. Defaults to the real one. */
spawn?: SpawnFn;
};
What a caller varies. Both default to the real thing.