asStream method
Creates a Stream containing the result of this operation.
This is like value.asStream()
, but if a subscription to the stream is
canceled, this is as well.
Implementation
Stream<T> asStream() {
var controller =
new StreamController<T>(sync: true, onCancel: _completer._cancel);
value.then((value) {
controller.add(value);
controller.close();
}, onError: (error, stackTrace) {
controller.addError(error, stackTrace);
controller.close();
});
return controller.stream;
}