nustack
ReferenceNucore

flows

Nu2 Flow atoms: the Command-composing sub-kind.

Module nu.core.flows.

Nu2 Flow atoms: the Command-composing sub-kind.

Two families plus the reactive set:

  • Strategy - compose mutating atoms directly: Sequential (>>), Parallel (|), Race (&), Gather, AnyN. Parallel also exposes forced-mode variants ParallelThreaded / ParallelAsync for explicit placement (Race / AnyN are async-only, no variants).
  • Control - compose bodies under Query parameters: IfDo, WhileDo, ForeverDo, ForEachDo, ForEachParAsync, ForEachParReactive, ForRangeDo, Delay, DelayedDo, SwitchDo. ForEachParAsync is the fan-out ForEach: one arm per element on the loop, all at once, joining on all. ForEachParReactive is that fan-out held open against a change subscription, one arm per element for as long as the element is there.
  • Reactive - consume change subscriptions and execute bodies in response: React, ReactWhile, ReactForever, Stream.

parallel.anyn

Module nu.core.flows.parallel.anyn.

AnyN: first-to-succeed fan-in over the async loop.

Full entries

NameSortCallMeaning
AnyNstrategyAnyN(*children)Runs its children concurrently; succeeds as soon as any one does.

control

Module nu.core.flows.control.

Control flows: Command-composing atoms steered by Query parameters.

Full entries

NameSortCallMeaning
DelaycontrolDelay(seconds)Delay(seconds) - sleeps seconds, then continues. No body.
DelayedDocontrolDelayedDo(delay, body)DelayedDo(delay, body) - sleeps delay seconds, then runs body.
ForEachDocontrolForEachDo(items, body, item='item')ForEachDo(items, body, item="item") - runs body once per element of items.
ForEachParAsynccontrolForEachParAsync(items, body, item='item')ForEachParAsync(items, body, item="item") - runs body once per element of items, every arm on the loop at once.
ForEachParReactivecontrolForEachParReactive(items, change, body, item='item')ForEachParReactive(items, change, body, item="item") - one arm per element, kept live against change.
ForRangeDocontrolForRangeDo(start, stop, body, step=1, index='index')ForRangeDo(start, stop, body, *, step=1, index="index") - runs body once per value of range(start, stop, step).
ForeverDocontrolForeverDo(body)ForeverDo(body) - runs body on loop forever.
IfDocontrolIfDo(cond, then, else_=None)IfDo(cond, then, else_=None) - runs then or else_ based on cond.
SwitchDocontrolSwitchDo(selector, cases, default=None)SwitchDo(selector, cases, default=None) - runs the case body keyed by selector's value.
WhileDocontrolWhileDo(cond, body)WhileDo(cond, body) - runs body on loop while cond stays truthy.

parallel.parallel

Module nu.core.flows.parallel.parallel.

Parallel: join-on-all fan-in, smart + forced variants.

Full entries

NameSortCallMeaning
GatherstrategyGather(*items)Alias of Parallel, named for reading naturally at a yield site.
ParallelstrategyParallel(*items)Runs its children concurrently and joins once every one has finished.
ParallelAsyncstrategyParallelAsync(*items)Parallel with every child forced onto the loop under async.
ParallelThreadedstrategyParallelThreaded(*items)Parallel with every child forced onto a worker thread under async.

noop

Module nu.core.flows.noop.

Noop: the empty Flow - the identity of flow composition.

Full entries

NameSortCallMeaning
NoopstrategyNoop()The empty Flow: composes nothing, the identity of flow composition.

parallel.race

Module nu.core.flows.parallel.race.

Race: first-to-complete fan-in over the async loop.

Full entries

NameSortCallMeaning
RacestrategyRace(*children)Runs its children concurrently; first to finish wins - the & composition.

raise_

Module nu.core.flows.raise_.

Raise: raise an exception at run time.

Full entries

NameSortCallMeaning
RaisecontrolRaise(msg, exc_cls=RuntimeError)Raise exc_cls(msg) at run time.
raise_flows.raise_(exc_cls, msg)Build a Raise node. Wrap in IfDo to gate.

react

Module nu.core.flows.react.

Reactive control flows: React, ReactWhile, ReactForever.

Full entries

NameSortCallMeaning
ReactcontrolReact(change, body=None, changed_key=None)Wait for one change on the subscription, run the body once, then stop.
ReactForevercontrolReactForever(change, body, changed_key=None)Run the body on every change, unconditionally, forever.
ReactWhilecontrolReactWhile(change, condition, body, changed_key=None)Run the body on each change while the condition stays truthy.

strategy

Module nu.core.flows.strategy.

Strategy flows: Command-composing atoms that dispatch their children.

Full entries

NameSortCallMeaning
SequentialstrategySequential(*children)Runs its children in order - the >> composition.

stream

Module nu.core.flows.stream.

Stream flow: drain-then-follow over ordered collections.

Full entries

NameSortCallMeaning
Streamstream_queryStream(source, body, key='stream_key', log_key='stream_log_key')Drain-then-follow over an ordered collection; cursor tracks position.

On this page