Skip to content

Flow

Generator-based control-flow helpers to compose synchronous and asynchronous workflows with typed effects, steps, exits, breaks, and dependency injection.

How to import?

The library exposes the DFlow and F namespaces from the main entry or via direct import (tree-shaking friendly), which lets you only load what you need.

typescript
import { DFlow, F } from "@duplojs/utils";
import * as DFlow from "@duplojs/utils/flow";
import * as F from "@duplojs/utils/flow";

Flow creation and execution

create

Creates a reusable flow object from a flow function.

run

Executes a flow and returns its final value.

exec

Executes a nested flow inside the current flow.

Execution coordination

These helpers keep internal state in WeakMaps keyed by the executed flow reference. To use them correctly across multiple calls, reuse a flow created with F.create(...) or a function returned by F.toFunction(...).

calledByNext

Calls a callback when a later run of the same flow replaces one that is still active.

queue

Serializes or limits concurrent runs of the same flow.

throttling

Ignores or defers runs that happen too close together for the same flow.

debounce

Waits before continuing the execution and cancels the previous run when a new one arrives.

Control flow

breakIf

Stops the current flow branch when a predicate matches.

exitIf

Exits the running flow when a predicate matches, even from nested flows.

step

Registers a named step and can optionally compute a value.

Lifecycle and cleanup

defer

Registers a cleanup callback executed when the flow finishes.

finalizer

Registers a final callback handled by the flow runner.

createInitializer

Creates an initializer that returns a value and automatically registers flow cleanup effects.

Dependencies

createDependence

Creates a typed dependency handler for the flow system.

inject

Requests a dependency from the flow runner.

Released under the MIT license.