Skip to content
Logo

chain

Composes handlers that compete for a request: each is offered it in turn, and the first one to accept wins — the handlers after it never run.

Use it when at most one handler owns a given request. See Composing Handlers for how it compares to broadcast.

Usage

await .({
    // the wallet claims portal deposits and declines everything else, which
    // then falls through to the application's own logic
    : (.handler, .handler),
});

Returns

A handler of the same request kind, ready to pass to run:

  • true as soon as one of the handlers accepts,
  • false if they all decline — run then rejects the input, since nobody claimed it. An empty chain() declines everything.

Exceptions are not caught: the first one aborts the remaining handlers and propagates to run, which rejects the input and emits the error as a report.

Parameters

handlers

  • Type: RequestHandler[]AdvanceRequestHandler or InspectRequestHandler
  • Variadic

The handlers, in the order they get offered the request. They may be synchronous or async, and always run one after another, never concurrently.

Each must return a real booleantrue claims the request, false declines it and passes it on. That is stricter than the handlers run takes directly, where returning nothing means accept; Handlers must answer explains why.

Errors

ConditionError
A handler answers with something other than a booleanTypeError

Ruled out by the types, so this only reaches JavaScript callers — as a rejected input with the error in a report, rather than a silently misrouted request.