このページはまだ翻訳されていないため、英語で表示されます。 翻訳に参加する

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.

FxEvents.value(T value) // of / just FxEvents.empty() // closes, no events FxEvents.fromFuture(Future<T> future) FxEvents.defer(Stream<T> Function() factory) // factory per listen FxEvents.generate(T initial, bool Function(T), T Function(T)) static FxEvents<int> FxEvents.timer(Duration delay, [Duration? every]) FxEvents.create(void Function(EventEmitter<T> emit) init) FxEvents.fromPattern(void Function(void Function(T)) add, void Function(void Function(T)) remove) static FxEvents<T> FxEvents.using<R, T>(R Function() acquire, Stream<T> Function(R) asStream, FutureOr<void> Function(R) release)

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.

Related: fxEvents — wrapping a Stream you already have · using — the pull-layer original: acquire on first pull, release once · share — when one run of a chain needs many listeners