Spec-Zone.ru › Dart 1

dart:async

Конструктор фабрики Stream.fromFuture

Stream.fromFuture(Future<T> future)

Создаёт новый одноподписной поток из будущего.

Когда будущее завершится, поток сгенерирует одно событие, либо данных, либо ошибки, а затем закроется с событием завершения.

Исходный код

factory Stream.fromFuture(Future<T> future) {
  // Use the controller's buffering to fill in the value even before
  // the stream has a listener. For a single value, it's not worth it
  // to wait for a listener before doing the `then` on the future.
  _StreamController<T> controller = new StreamController<T>(sync: true);
  future.then((value) {
    controller._add(value);
    controller._closeUnchecked();
  }, onError: (error, stackTrace) {
    controller._addError(error, stackTrace);
    controller._closeUnchecked();
  });
  return controller.stream;
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/1.24.3/dart-async/Stream/Stream.fromFuture.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API