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:
trueas soon as one of the handlers accepts,falseif they all decline —runthen rejects the input, since nobody claimed it. An emptychain()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[]—AdvanceRequestHandlerorInspectRequestHandler - 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 boolean — true 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
| Condition | Error |
|---|---|
| A handler answers with something other than a boolean | TypeError |
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.