Movatterモバイル変換


[0]ホーム

URL:


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

asyncExpand<E> method

Stream<E>asyncExpand<E>(
  1. Stream<E>?convert(
    1. Tevent
    )
)

Transforms each element into a sequence of asynchronous events.

Returns a new stream and for each event of this stream, do the following:

  • If the event is an error event or a done event, it is emitted directlyby the returned stream.
  • Otherwise it is an element. Then theconvert function is calledwith the element as argument to produce a convert-stream for the element.
  • If that call throws, the error is emitted on the returned stream.
  • If the call returnsnull, no further action is taken for the elements.
  • Otherwise, this stream is paused and convert-stream is listened to.Every data and error event of the convert-stream is emitted on the returnedstream in the order it is produced.When the convert-stream ends, this stream is resumed.

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

Implementation

Stream<E> asyncExpand<E>(Stream<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,    );    subscription.onData((T event) {      Stream<E>? newStream;      try {        newStream = convert(event);      } catch (e, s) {        var error = _interceptCaughtError(e, s);        controller.addError(error.error, error.stackTrace);        return;      }      if (newStream != null) {        subscription.pause();        controller.addStream(newStream).whenComplete(subscription.resume);      }    });    controller.onCancel = subscription.cancel;    if (!isBroadcast) {      controller        ..onPause = subscription.pause        ..onResume = subscription.resume;    }  };  return controller.stream;}
  1. Dart
  2. dart:async
  3. Stream<T>
  4. asyncExpand<E> method
Stream class

[8]ページ先頭

©2009-2025 Movatter.jp