asyncMapBuffer<S> method

Stream<S> asyncMapBuffer<S>(
  1. Future<S> convert(
    1. List<T>
    )
)

Like asyncMap but events are buffered until previous events have been processed by convert.

If this stream is a broadcast stream the result will be as well. When used with a broadcast stream behavior also differs from asyncMap in that the convert function is only called once per event, rather than once per listener per event.

The first event from this stream is always passed to convert as a list with a single element. After that, events are buffered until the previous Future returned from convert has completed.

Errors from this stream are forwarded directly to the result stream. Errors during the conversion are also forwarded to the result stream and are considered completing work so the next values are let through.

The result stream will not close until this stream closes and all pending conversions have finished.

Implementation

Stream<S> asyncMapBuffer<S>(Future<S> Function(List<T>) convert) {
  var workFinished = StreamController<void>()
    // Let the first event through.
    ..add(null);
  return buffer(workFinished.stream)._asyncMapThen(convert, workFinished.add);
}