nustack
ReferenceCore

nu.flows

Command-composing atoms. A Flow owns no effects and yields nothing (VOID) - either it fans out to mutating children directly (Strategy), or it steers a mutating body under Query parameters (Control), or it drives a body off a change subscription (the reactive Controls) or an ordered collection (Stream). Flat-exported at nu.*.

from nu import Sequential, Parallel, Race, Gather, AnyN, IfDo, WhileDo, ForeverDo, ForEachDo, ForRangeDo, Delay, DelayedDo, SwitchDo, React, ReactWhile, ReactForever, Stream, Raise, raise_, Noop

Strategy

Compose mutating atoms directly, no Query parameters. Sequential runs children in order (>>); Parallel/Race/Gather/AnyN run them concurrently, dispatched through the Runtime's fan-in primitives. Race and AnyN are async-only.

NameSortSignatureEffectMeaning
SequentialFlow(Strategy)Sequential(*children)mutatesrun children in order (>>)
ParallelFlow(Strategy)Parallel(*children)mutatesrun children concurrently, join on all (|)
RaceFlow(Strategy)Race(*children)mutates, async-onlyrun children concurrently, first to finish wins (&), cancels the rest
GatherFlow(Strategy)Gather(*children)mutatesrun children concurrently, join on all (yield-collecting twin of Parallel)
AnyNFlow(Strategy)AnyN(*children)mutates, async-onlyrun children concurrently, succeed on first success, cancels the rest
NoopFlow(Strategy)Noop()nonethe empty Flow - identity of flow composition

Control

Compose a mutating body under Query parameters (a condition, an iterable, a count). A Control owns no effects and yields nothing; param slots feed the orchestration, body slots carry the writes.

NameSortSignatureEffectMeaning
IfDoFlow(Control)IfDo(cond, then, else_=None)mutatesrun then if cond is truthy, else else_
WhileDoFlow(Control)WhileDo(cond, body)mutatesrun body while cond is truthy
ForeverDoFlow(Control)ForeverDo(body)mutatesrun body endlessly
ForEachDoFlow(Control)ForEachDo(items, body, item="item")mutatesrun body for each element, bound under name item
ForRangeDoFlow(Control)ForRangeDo(start, stop, body, *, step=1, index="index")mutatescounted loop over range(start, stop, step), index bound under name index
DelayFlow(Control)Delay(seconds)nonesleep seconds, no body
DelayedDoFlow(Control)DelayedDo(delay, body)mutatessleep delay seconds, then run body
SwitchDoFlow(Control)SwitchDo(selector, cases, default=None)mutatesbranch on selector value, first matching case's body runs, else default
RaiseFlow(Control)Raise(msg, *, exc_cls=RuntimeError)noneraise exc_cls(msg) at run time; skipped if msg resolves to EMPTY/INVALID

raise_(exc_cls, msg) is a plain function wrapper around Raise - raise_(ValueError, "bad") builds Raise("bad", exc_cls=ValueError). Wrap in IfDo to gate.

Reactive

Subscribe to a change event and run a body in response; yields nothing. A change notification bridges into async via asyncio.Queue. Async-only.

NameSortSignatureEffectMeaning
ReactFlow(Control)React(change, body=None, *, changed_key=None)mutates, async-onlywait for one change event, run body once (if given)
ReactWhileFlow(Control)ReactWhile(change, condition, body, *, changed_key=None)mutates, async-onlyrun body on each change event while condition is truthy
ReactForeverFlow(Control)ReactForever(change, body, *, changed_key=None)mutates, async-onlyrun body on every change event, forever

Stream

Drain-then-follow over an ordered collection - the cat file; tail -f of Nu. Observes via a cursor and a reactive subscription, yielding body results across the batch-catch-up-then-live-follow transition.

NameSortSignatureEffectMeaning
StreamStreamQueryStream(source, body, *, key="stream_key", log_key="stream_log_key")pure, async-onlydrain existing items via cursor, then follow new ones reactively

On this page