Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "stream-sync"

Index

Classes

Interfaces

Type aliases

Functions

Type aliases

SyncTuple

SyncTuple<T>: {}

Type parameters

Type declaration

    Functions

    Const sync

    • Similar to StreamMerge, but with extra synchronization of inputs. Before emitting any new values, StreamSync collects values until at least one has been received from all inputs. Once that's the case, the collected values are sent as labeled tuple object to downstream subscribers.

      remarks

      Each value in the emitted tuple objects is stored under their input stream's ID. Only the last value received from each input is passed on. After the initial tuple has been emitted, you can choose from two possible behaviors:

      1. Any future change in any input will produce a new result tuple. These tuples will retain the most recently read values from other inputs. This behavior is the default and illustrated in the above schematic.
      2. If the reset option is true, every input will have to provide at least one new value again until another result tuple is produced.

      Any done inputs are automatically removed. By default, StreamSync calls ISubscriber.done when the last active input is done, but this behavior can be overridden via the provided options.

      Input streams can be added and removed dynamically and the emitted tuple size adjusts to the current number of inputs (the next time a value is received from any input). After an input is removed (or done) its last received value can also be removed from the result tuple. This behavior can be configured via the clean option given to sync() (disabled by default).

      If the reset option is enabled, the last emitted tuple is allowed to be incomplete, by default. To only allow complete tuples, also set the all option to false.

      The synchronization is done via the {@link @thi.ng/transducers#(partitionSync:1)} transducer from the {@link @thi.ng/transducers# | @thi.ng/transducers} package. See this function's docs for further details.

      example
      const a = stream();
      const b = stream();
      s = sync({ src: { a, b } }).subscribe(trace("result: "));
      a.next(1);
      b.next(2);
      // result: { a: 1, b: 2 }

      Also see: StreamSyncOpts

      Type parameters

      Parameters

      Returns StreamSync<A, B>

    Generated using TypeDoc