Обзор
functionCore Runtime

run

Runs a behavior with an optional application context.

Signature

tsSignature
export async function run<I, O, E, C extends object = {}>(
behavior: Behavior<I, O, E, C>,
input: I,
context: C & { signal?: AbortSignal } = {} as C & { signal?: AbortSignal },
): Promise<Result<O, E | RuntimeError>>;

Imports

tsImport
import { run } from "@/lib/flow/core/runtime";
import { run } from "@/lib/flow";

Type Parameters

I

Input type.

O

Output type.

E

Expected domain error type.

C

Custom context type.

Parameters

behavior
Behavior<I, O, E, C>

Behavior to execute.

input
I

Input passed to the behavior.

context
C & { signal?: AbortSignal }

Optional custom context and optional `AbortSignal`.

Returns

A result containing behavior output, domain error, or runtime error.

Return type
Promise<Result<O, E | RuntimeError>>

Details

If no signal is provided, Flow creates a fresh non-aborted signal. Expected failures remain in

the returned `Result`; thrown exceptions are converted to `Thrown`.

Examples

tsExample
const result = await run(loadUser, "user_1");
Behavior

Executable Flow workflow unit.

type
input

Creates an identity behavior for starting typed pipelines.

function
Result

Explicit success-or-failure outcome used throughout Flow.

type
RuntimeError

Runtime-level failure union added around every behavior's domain error type.

type
thrown

Re-exports core result helpers used by advanced record internals.

re-export
Thrown

Runtime error returned when user code throws.

type

Source

tsflow/core/runtime.ts:192-203
export async function run<I, O, E, C extends object = {}>(
behavior: Behavior<I, O, E, C>,
input: I,
context: C & { signal?: AbortSignal } = {} as C & { signal?: AbortSignal },
): Promise<Result<O, E | RuntimeError>> {
const { signal = new AbortController().signal, ...rest } = context;
return runBehavior(behavior, input, {
...(rest as C),
signal,
});
}