Movatterモバイル変換


[0]ホーム

URL:


menu
  1. Dart
  2. dart:async
  3. Stream<T>
  4. asyncMap<E> method
asyncMap
description

asyncMap<E> method

Stream<E>asyncMap<E>(
  1. FutureOr<E>convert(
    1. Tevent
    )
)

Creates a new stream with each data event of this stream asynchronouslymapped to a new event.

This acts likemap, in thatconvert function is called once perdata event, but hereconvert may be asynchronous and return aFuture.If that happens, this stream waits for that future to complete beforecontinuing with further events.

The returned stream is a broadcast stream if this stream is.

Implementation

Stream<E> asyncMap<E>(FutureOr<E> convert(T event)) {  _StreamControllerBase<E> controller;  if (isBroadcast) {    controller = _SyncBroadcastStreamController<E>(null, null);  } else {    controller = _SyncStreamController<E>(null, null, null, null);  }  controller.onListen = () {    StreamSubscription<T> subscription = this.listen(      null,      onError: controller._addError, // Avoid Zone error replacement.      onDone: controller.close,    );    FutureOr<Null> add(E value) {      controller.add(value);    }    final addError = controller._addError;    final resume = subscription.resume;    subscription.onData((T event) {      FutureOr<E> newValue;      try {        newValue = convert(event);      } catch (e, s) {        var error = _interceptCaughtError(e, s);        controller.addError(error.error, error.stackTrace);        return;      }      if (newValue is Future<E>) {        subscription.pause();        newValue.then(add, onError: addError).whenComplete(resume);      } else {        controller.add(newValue);      }    });    controller.onCancel = subscription.cancel;    if (!isBroadcast) {      controller        ..onPause = subscription.pause        ..onResume = resume;    }  };  return controller.stream;}
  1. Dart
  2. dart:async
  3. Stream<T>
  4. asyncMap<E> method
Stream class

[8]ページ先頭

©2009-2025 Movatter.jp