constructors
Cold constructors for an event chain: a value, an empty close, a future, a generator, a create callback — no Stream you already had to wrap.
Lecture
fxEvents(stream) wraps a
stream you already have. These constructors
are the stream. They stay cold: wrapping or naming
them listens to nothing; a terminal
(toList, head, listen) is
what starts events flowing. That is the same honesty rule the rest
of the chain keeps.
The simple ones first. FxEvents.value(x) emits
x and closes — Rx's of/just.
FxEvents.empty() closes with nothing.
FxEvents.never() never emits and never closes;
listening hangs until cancelled, so it is a mention, not a demo.
fromFuture emits the future's value (or its error) and
closes; the future is not observed until a listener arrives.
generate(initial, condition, iterate) walks
initial, iterate(initial), … while the condition
holds — each step is a timer tick, so an infinite generator can
still be cancelled.
Time, then factories. FxEvents.timer(delay) emits
0 after the delay and closes; with
every it continues 1, 2, … on that
period. periodic is the never-completing clock
(tick count when the computation is omitted) — cancel it; do not
toList it. defer(factory) builds a fresh
inner stream on every listen — the factory, not the wrapper; the
chain stays single-subscription. using acquires a
resource on listen, mirrors it, and releases exactly once — the
push counterpart of pull
using.
fromPattern(add, remove) is the typical
on/off bridge. And
create(init) calls init with an
EventEmitter: add, addError,
close, and onCancel for teardown. A throw
from init is forwarded and the stream closes.
fxdart events layer, after Rx's of/just,
EMPTY, NEVER, from,
interval, timer, defer,
generate, fromEventPattern,
using, and the Observable constructor /
create.
Demo 1 · value, empty, generate
Demo 2 · defer, and fromFuture
Try it yourself
Exercise: create that emits 1, 2, 3, then closes.