Genel bakış
functionComposition

sequence

Runs two behaviors left-to-right.

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

A

First behavior input type.

B

First output and second input type.

D

Second behavior output type.

E1

First behavior domain error type.

E2

Second behavior domain error type.

C

Shared custom context type.

Parameters

first
Behavior<A, B, E1, C>

Behavior to run first.

second
Behavior<B, D, E2, C>

Behavior to run after first success.

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);
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);
};
}