| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // Default implementation of a stream with a controller for adding | 8 // Default implementation of a stream with a controller for adding |
| 9 // events to the stream. | 9 // events to the stream. |
| 10 // ------------------------------------------------------------------- | 10 // ------------------------------------------------------------------- |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 * When the done event is fired to a subscriber, the subscriber is automatically | 35 * When the done event is fired to a subscriber, the subscriber is automatically |
| 36 * unsubscribed. | 36 * unsubscribed. |
| 37 */ | 37 */ |
| 38 class StreamController<T> extends Stream<T> implements StreamSink<T> { | 38 class StreamController<T> extends Stream<T> implements StreamSink<T> { |
| 39 _StreamImpl<T> _stream; | 39 _StreamImpl<T> _stream; |
| 40 Stream<T> get stream => _stream; | 40 Stream<T> get stream => _stream; |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * A controller with a [stream] that supports multiple subscribers. | 43 * A controller with a [stream] that supports multiple subscribers. |
| 44 */ | 44 */ |
| 45 StreamController() { | 45 StreamController.multiSubscription() { |
| 46 _stream = new _MultiControllerStream<T>(onSubscriptionStateChange, | 46 _stream = new _MultiControllerStream<T>(onSubscriptionStateChange, |
| 47 onPauseStateChange); | 47 onPauseStateChange); |
| 48 } | 48 } |
| 49 /** | 49 /** |
| 50 * A controller with a [stream] that supports only one single subscriber. | 50 * A controller with a [stream] that supports only one single subscriber. |
| 51 * The controller will buffer all incoming events until the subscriber is | 51 * The controller will buffer all incoming events until the subscriber is |
| 52 * registered. | 52 * registered. |
| 53 */ | 53 */ |
| 54 StreamController.singleSubscription() { | 54 StreamController() { |
| 55 _stream = new _SingleControllerStream<T>(onSubscriptionStateChange, | 55 _stream = new _SingleControllerStream<T>(onSubscriptionStateChange, |
| 56 onPauseStateChange); | 56 onPauseStateChange); |
| 57 } | 57 } |
| 58 | 58 |
| 59 StreamSubscription listen(void onData(T data), | 59 StreamSubscription listen(void onData(T data), |
| 60 { void onError(AsyncError error), | 60 { void onError(AsyncError error), |
| 61 void onDone(), | 61 void onDone(), |
| 62 bool unsubscribeOnError}) { | 62 bool unsubscribeOnError}) { |
| 63 return _stream.listen(onData, | 63 return _stream.listen(onData, |
| 64 onError: onError, | 64 onError: onError, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 _SingleControllerStream(this._subscriptionHandler, this._pauseHandler); | 163 _SingleControllerStream(this._subscriptionHandler, this._pauseHandler); |
| 164 | 164 |
| 165 void _onSubscriptionStateChange() { | 165 void _onSubscriptionStateChange() { |
| 166 _subscriptionHandler(); | 166 _subscriptionHandler(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void _onPauseStateChange() { | 169 void _onPauseStateChange() { |
| 170 _pauseHandler(); | 170 _pauseHandler(); |
| 171 } | 171 } |
| 172 } | 172 } |
| OLD | NEW |