Signature
tsSignature
export function sequence<A, B, D, E1, E2, C extends object>( first: Behavior<A, B, E1, C>, second: Behavior<B, D, E2, C>,): Behavior<A, D, E1 | E2, C>;Imports
tsImport
import { sequence } from "@/lib/flow/sequence";import { sequence } from "@/lib/flow";Type Parameters
AFirst behavior input type.
BFirst output and second input type.
DSecond behavior output type.
E1First behavior domain error type.
E2Second behavior domain error type.
CShared custom context type.
Parameters
Returns
A behavior with the first input type, second output type, and unioned domain errors.
Return type
Behavior<A, D, E1 | E2, C>Details
The second behavior receives the first behavior's successful output. If the first behavior
fails, the second behavior is skipped and the failure passes through.
Examples
tsExample
const loadName = sequence(loadUser, extractName);Related Symbols
Behavior
Executable Flow workflow unit.
type
Source
tsflow/sequence.ts:24-45
export function sequence<A, B, D, E1, E2, C extends object>( first: Behavior<A, B, E1, C>, second: Behavior<B, D, E2, C>,): Behavior<A, D, E1 | E2, C> { return async (input: A, context: RuntimeContext<C>) => { if (context.signal.aborted) { return resultFromSignal(context.signal); }
const firstResult = await runBehavior(first, input, context);
if (!firstResult.ok) { return firstResult; }
if (context.signal.aborted) { return resultFromSignal(context.signal); }
return runBehavior(second, firstResult.value, context); };}