| 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 bool get isSingleSubscription => _stream.isSingleSubscription; | 59 bool get isSingleSubscription => _stream.isSingleSubscription; |
| 60 | 60 |
| 61 StreamSubscription listen(void onData(T data), | 61 StreamSubscription listen(void onData(T data), |
| 62 { void onError(AsyncError error), | 62 { void onError(AsyncError error), |
| 63 void onDone(), | 63 void onDone(), |
| 64 bool unsubscribeOnError}) { | 64 bool unsubscribeOnError}) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 _SingleControllerStream(this._subscriptionHandler, this._pauseHandler); | 165 _SingleControllerStream(this._subscriptionHandler, this._pauseHandler); |
| 166 | 166 |
| 167 void _onSubscriptionStateChange() { | 167 void _onSubscriptionStateChange() { |
| 168 _subscriptionHandler(); | 168 _subscriptionHandler(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void _onPauseStateChange() { | 171 void _onPauseStateChange() { |
| 172 _pauseHandler(); | 172 _pauseHandler(); |
| 173 } | 173 } |
| 174 } | 174 } |
| OLD | NEW |