Future forEach(void action(T element))

Executes action on each data event of the stream.

Completes the returned Future when all events of the stream have been processed. Completes the future with an error if the stream has an error event, or if action throws.


Future forEach(void action(T element)) {
  _Future future = new _Future();
  StreamSubscription subscription;
  subscription = this.listen(
      (T element) {
          () => action(element),
          (_) {},
          _cancelAndErrorClosure(subscription, future)
      onError: future._completeError,
      onDone: () {
      cancelOnError: true);
  return future;