Signature
export function task<I, O, E = never, C extends object = {}>( run: (input: I, context: TaskContext<C>) => Awaitable<TaskReturn<O, E>>,): Behavior<I, O, E, C>;Imports
import { task } from "@/lib/flow/task";import { task } 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 that wraps plain values in `ok` and preserves explicit results.
Behavior<I, O, E, C>Details
`task` is the main authoring boundary for Flow programs. Return plain values for success or use
`context.fail`/`context.err` for typed domain failures. Thrown exceptions are captured by the
runtime as `Thrown` errors.
Examples
const loadUser = task<string, { id: string }, { kind: "missing" }>((id, context) => { if (!id) return context.fail({ kind: "missing" }); return { id };});Related Symbols
Represents a value that may be returned directly or through a Promise.
Executable Flow workflow unit.
Re-exports core result helpers used by advanced record internals.
Creates a behavior that always fails with the same domain error.
Creates an identity behavior for starting typed pipelines.
Runs a behavior with an optional application context.
Runtime context provided to a `task` callback.
Source
export function task<I, O, E = never, C extends object = {}>( run: (input: I, context: TaskContext<C>) => Awaitable<TaskReturn<O, E>>,): Behavior<I, O, E, C> { return define(async (input: I, context: RuntimeContext<C>) => { const result = await run(input, { ...context, ok, succeed: ok, fail: err, err, });
return isResult(result) ? result : ok(result); });}