buffer method

Stream<List<T>> buffer(
  1. Stream<void> trigger, {
  2. bool longPoll = true,
})

Buffers the values emitted on this stream and emits them when trigger emits an event.

If longPoll is false, if there are no buffered values when trigger emits an empty list is immediately emitted.

If longPoll is true, and there are no buffered values when trigger emits one or more events, then the next value from this stream is immediately emitted on the returned stream as a single element list. Subsequent events on trigger while there have been no events on this stream are ignored.

The result stream will close as soon as there is a guarantee it will not emit any more events. There will not be any more events emitted if:

  • trigger is closed and there is no waiting long poll.
  • Or, this stream is closed and previously buffered events have been delivered.

If this stream is a broadcast stream, the result will be as well. Errors from this stream or the trigger are immediately forwarded to the output.

See also:

  • sample which use a trigger stream in the same way, but keeps only the most recent source event.

Implementation

Stream<List<T>> buffer(Stream<void> trigger, {bool longPoll = true}) =>
    aggregateSample(
        trigger: trigger,
        aggregate: _collect,
        longPoll: longPoll,
        onEmpty: _empty);