Signature
tsSignature
export function define<I, O, E = unknown, C extends object = {}>( run: (input: I, context: RuntimeContext<C>) => Awaitable<Result<O, E>>,): Behavior<I, O, E, C>;Imports
tsImport
import { define } from "@/lib/flow/core/runtime";import { define } from "@/lib/flow";Type Parameters
IInput type.
OOutput type.
EExpected domain error type.
CCustom context type.
Parameters
runCallback invoked for each behavior execution.
Returns
A behavior protected by cancellation and thrown-exception handling.
Return type
Behavior<I, O, E, C>Details
Use `define` for low-level helpers that already operate in the result channel. Most application
code should use `task`, which also accepts plain successful values.
Related Symbols
Awaitable
Represents a value that may be returned directly or through a Promise.
type
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
run
Runs a behavior with an optional application context.
function
RuntimeContext
Execution context passed to every behavior.
type
Source
tsflow/core/runtime.ts:146-170
export function define<I, O, E = unknown, C extends object = {}>( run: (input: I, context: RuntimeContext<C>) => Awaitable<Result<O, E>>,): Behavior<I, O, E, C> { return async (input, context) => { if (context.signal.aborted) { return resultFromSignal(context.signal); }
try { const result = await run(input, context);
if (context.signal.aborted) { return resultFromSignal(context.signal); }
return result; } catch (error) { if (context.signal.aborted) { return cancelled(context.signal.reason); }
return thrown(error); } };}