| 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 // Controller for creating and adding events to a stream. | 8 // Controller for creating and adding events to a stream. |
| 9 // ------------------------------------------------------------------- | 9 // ------------------------------------------------------------------- |
| 10 | 10 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * A controller with a broadcast [stream].. | 53 * A controller with a broadcast [stream].. |
| 54 * | 54 * |
| 55 * The [onPauseStateChange] function is called when the stream becomes | 55 * The [onPauseStateChange] function is called when the stream becomes |
| 56 * paused or resumes after being paused. The current pause state can | 56 * paused or resumes after being paused. The current pause state can |
| 57 * be read from [isPaused]. Ignored if [:null:]. | 57 * be read from [isPaused]. Ignored if [:null:]. |
| 58 * | 58 * |
| 59 * The [onSubscriptionStateChange] function is called when the stream | 59 * The [onSubscriptionStateChange] function is called when the stream |
| 60 * receives its first listener or loses its last. The current subscription | 60 * receives its first listener or loses its last. The current subscription |
| 61 * state can be read from [hasSubscribers]. Ignored if [:null:]. | 61 * state can be read from [hasListener]. Ignored if [:null:]. |
| 62 */ | 62 */ |
| 63 StreamController.broadcast({void onPauseStateChange(), | 63 StreamController.broadcast({void onPauseStateChange(), |
| 64 void onSubscriptionStateChange()}) | 64 void onSubscriptionStateChange()}) |
| 65 : stream = new _MultiControllerStream<T>(onSubscriptionStateChange, | 65 : stream = new _MultiControllerStream<T>(onSubscriptionStateChange, |
| 66 onPauseStateChange); | 66 onPauseStateChange); |
| 67 | 67 |
| 68 /** | 68 /** |
| 69 * A controller with a [stream] that supports only one single subscriber. | 69 * A controller with a [stream] that supports only one single subscriber. |
| 70 * | 70 * |
| 71 * The controller will buffer all incoming events until the subscriber is | 71 * The controller will buffer all incoming events until the subscriber is |
| 72 * registered. | 72 * registered. |
| 73 * | 73 * |
| 74 * The [onPauseStateChange] function is called when the stream becomes | 74 * The [onPauseStateChange] function is called when the stream becomes |
| 75 * paused or resumes after being paused. The current pause state can | 75 * paused or resumes after being paused. The current pause state can |
| 76 * be read from [isPaused]. Ignored if [:null:]. | 76 * be read from [isPaused]. Ignored if [:null:]. |
| 77 * | 77 * |
| 78 * The [onSubscriptionStateChange] function is called when the stream | 78 * The [onSubscriptionStateChange] function is called when the stream |
| 79 * receives its first listener or loses its last. The current subscription | 79 * receives its first listener or loses its last. The current subscription |
| 80 * state can be read from [hasSubscribers]. Ignored if [:null:]. | 80 * state can be read from [hasListener]. Ignored if [:null:]. |
| 81 */ | 81 */ |
| 82 StreamController({void onPauseStateChange(), | 82 StreamController({void onPauseStateChange(), |
| 83 void onSubscriptionStateChange()}) | 83 void onSubscriptionStateChange()}) |
| 84 : stream = new _SingleControllerStream<T>(onSubscriptionStateChange, | 84 : stream = new _SingleControllerStream<T>(onSubscriptionStateChange, |
| 85 onPauseStateChange); | 85 onPauseStateChange); |
| 86 | 86 |
| 87 /** | 87 /** |
| 88 * Returns a view of this object that only exposes the [EventSink] interface. | 88 * Returns a view of this object that only exposes the [EventSink] interface. |
| 89 */ | 89 */ |
| 90 EventSink<T> get sink => new EventSinkView<T>(this); | 90 EventSink<T> get sink => new EventSinkView<T>(this); |
| 91 | 91 |
| 92 /** | 92 /** |
| 93 * Whether the stream is closed for adding more events. | 93 * Whether the stream is closed for adding more events. |
| 94 * | 94 * |
| 95 * If true, the "done" event might not have fired yet, but it has been | 95 * If true, the "done" event might not have fired yet, but it has been |
| 96 * scheduled, and it is too late to add more events. | 96 * scheduled, and it is too late to add more events. |
| 97 */ | 97 */ |
| 98 bool get isClosed => stream._isClosed; | 98 bool get isClosed => stream._isClosed; |
| 99 | 99 |
| 100 /** Whether one or more active subscribers have requested a pause. */ | 100 /** Whether one or more active subscribers have requested a pause. */ |
| 101 bool get isPaused => stream._isInputPaused; | 101 bool get isPaused => stream._isInputPaused; |
| 102 | 102 |
| 103 /** Whether there are currently any subscribers on this [Stream]. */ | 103 /** Whether there are currently any subscribers on this [Stream]. */ |
| 104 bool get hasSubscribers => stream._hasSubscribers; | 104 bool get hasListener => stream._hasListener; |
| 105 | 105 |
| 106 /** | 106 /** |
| 107 * Send or queue a data event. | 107 * Send or queue a data event. |
| 108 */ | 108 */ |
| 109 void add(T value) => stream._add(value); | 109 void add(T value) => stream._add(value); |
| 110 | 110 |
| 111 /** | 111 /** |
| 112 * Send or enqueue an error event. | 112 * Send or enqueue an error event. |
| 113 * | 113 * |
| 114 * If [error] is not an [AsyncError], [error] and an optional [stackTrace] | 114 * If [error] is not an [AsyncError], [error] and an optional [stackTrace] |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 void _onPauseStateChange() { | 187 void _onPauseStateChange() { |
| 188 if (_pauseHandler != null) { | 188 if (_pauseHandler != null) { |
| 189 try { | 189 try { |
| 190 _pauseHandler(); | 190 _pauseHandler(); |
| 191 } catch (e, s) { | 191 } catch (e, s) { |
| 192 new AsyncError(e, s).throwDelayed(); | 192 new AsyncError(e, s).throwDelayed(); |
| 193 } | 193 } |
| 194 } | 194 } |
| 195 } | 195 } |
| 196 } | 196 } |
| OLD | NEW |