| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart.async; | 5 part of dart.async; |
| 6 | 6 |
| 7 // ------------------------------------------------------------------- | 7 // ------------------------------------------------------------------- |
| 8 // Core Stream types | 8 // Core Stream types |
| 9 // ------------------------------------------------------------------- | 9 // ------------------------------------------------------------------- |
| 10 | 10 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 /** | 77 /** |
| 78 * Creates a new single-subscription stream from the future. | 78 * Creates a new single-subscription stream from the future. |
| 79 * | 79 * |
| 80 * When the future completes, the stream will fire one event, either | 80 * When the future completes, the stream will fire one event, either |
| 81 * data or error, and then close with a done-event. | 81 * data or error, and then close with a done-event. |
| 82 */ | 82 */ |
| 83 factory Stream.fromFuture(Future<T> future) { | 83 factory Stream.fromFuture(Future<T> future) { |
| 84 // Use the controller's buffering to fill in the value even before | 84 // Use the controller's buffering to fill in the value even before |
| 85 // the stream has a listener. For a single value, it's not worth it | 85 // the stream has a listener. For a single value, it's not worth it |
| 86 // to wait for a listener before doing the `then` on the future. | 86 // to wait for a listener before doing the `then` on the future. |
| 87 _StreamController<T> controller = new StreamController<T>(sync: true); | 87 _StreamController<T> controller = |
| 88 new StreamController<T>(sync: true) as _StreamController<T>; |
| 88 future.then((value) { | 89 future.then((value) { |
| 89 controller._add(value); | 90 controller._add(value); |
| 90 controller._closeUnchecked(); | 91 controller._closeUnchecked(); |
| 91 }, | 92 }, |
| 92 onError: (error, stackTrace) { | 93 onError: (error, stackTrace) { |
| 93 controller._addError(error, stackTrace); | 94 controller._addError(error, stackTrace); |
| 94 controller._closeUnchecked(); | 95 controller._closeUnchecked(); |
| 95 }); | 96 }); |
| 96 return controller.stream; | 97 return controller.stream; |
| 97 } | 98 } |
| (...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1402 | 1403 |
| 1403 | 1404 |
| 1404 /** [Stream] wrapper that only exposes the [Stream] interface. */ | 1405 /** [Stream] wrapper that only exposes the [Stream] interface. */ |
| 1405 class StreamView<T> extends Stream<T> { | 1406 class StreamView<T> extends Stream<T> { |
| 1406 Stream<T> _stream; | 1407 Stream<T> _stream; |
| 1407 | 1408 |
| 1408 StreamView(this._stream); | 1409 StreamView(this._stream); |
| 1409 | 1410 |
| 1410 bool get isBroadcast => _stream.isBroadcast; | 1411 bool get isBroadcast => _stream.isBroadcast; |
| 1411 | 1412 |
| 1412 Stream<T> asBroadcastStream({void onListen(StreamSubscription subscription), | 1413 Stream<T> asBroadcastStream({void onListen(StreamSubscription<T> subscription)
, |
| 1413 void onCancel(StreamSubscription subscription)}) | 1414 void onCancel(StreamSubscription<T> subscription)
}) |
| 1414 => _stream.asBroadcastStream(onListen: onListen, onCancel: onCancel); | 1415 => _stream.asBroadcastStream(onListen: onListen, onCancel: onCancel); |
| 1415 | 1416 |
| 1416 StreamSubscription<T> listen(void onData(T value), | 1417 StreamSubscription<T> listen(void onData(T value), |
| 1417 { Function onError, | 1418 { Function onError, |
| 1418 void onDone(), | 1419 void onDone(), |
| 1419 bool cancelOnError }) { | 1420 bool cancelOnError }) { |
| 1420 return _stream.listen(onData, onError: onError, onDone: onDone, | 1421 return _stream.listen(onData, onError: onError, onDone: onDone, |
| 1421 cancelOnError: cancelOnError); | 1422 cancelOnError: cancelOnError); |
| 1422 } | 1423 } |
| 1423 } | 1424 } |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1659 class _ControllerEventSinkWrapper<T> implements EventSink<T> { | 1660 class _ControllerEventSinkWrapper<T> implements EventSink<T> { |
| 1660 EventSink _sink; | 1661 EventSink _sink; |
| 1661 _ControllerEventSinkWrapper(this._sink); | 1662 _ControllerEventSinkWrapper(this._sink); |
| 1662 | 1663 |
| 1663 void add(T data) { _sink.add(data); } | 1664 void add(T data) { _sink.add(data); } |
| 1664 void addError(error, [StackTrace stackTrace]) { | 1665 void addError(error, [StackTrace stackTrace]) { |
| 1665 _sink.addError(error, stackTrace); | 1666 _sink.addError(error, stackTrace); |
| 1666 } | 1667 } |
| 1667 void close() { _sink.close(); } | 1668 void close() { _sink.close(); } |
| 1668 } | 1669 } |
| OLD | NEW |