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 // States shared by single/multi stream implementations. | 7 // States shared by single/multi stream implementations. |
8 | 8 |
9 /// Initial and default state where the stream can receive and send events. | 9 /// Initial and default state where the stream can receive and send events. |
10 const int _STREAM_OPEN = 0; | 10 const int _STREAM_OPEN = 0; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 _handlePendingEvents(); | 116 _handlePendingEvents(); |
117 } | 117 } |
118 | 118 |
119 /** | 119 /** |
120 * Send or enqueue a "done" message. | 120 * Send or enqueue a "done" message. |
121 * | 121 * |
122 * The "done" message should be sent at most once by a stream, and it | 122 * The "done" message should be sent at most once by a stream, and it |
123 * should be the last message sent. | 123 * should be the last message sent. |
124 */ | 124 */ |
125 void _close() { | 125 void _close() { |
126 if (_isClosed) throw new StateError("Sending on closed stream"); | 126 if (_isClosed) return; |
Mads Ager (google)
2013/02/21 10:39:02
We should land this file on bleeding_edge. It is a
Søren Gjesse
2013/02/21 11:44:25
Anders did.
| |
127 _state |= _STREAM_CLOSED; | 127 _state |= _STREAM_CLOSED; |
128 if (!_canFireEvent) { | 128 if (!_canFireEvent) { |
129 // You can't enqueue an event after the Done, so make it const. | 129 // You can't enqueue an event after the Done, so make it const. |
130 _addPendingEvent(const _DelayedDone()); | 130 _addPendingEvent(const _DelayedDone()); |
131 return; | 131 return; |
132 } | 132 } |
133 _sendDone(); | 133 _sendDone(); |
134 assert(!_hasPendingEvent); | 134 assert(!_hasPendingEvent); |
135 } | 135 } |
136 | 136 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 */ | 303 */ |
304 void _addListener(_StreamSubscriptionImpl subscription); | 304 void _addListener(_StreamSubscriptionImpl subscription); |
305 | 305 |
306 /** | 306 /** |
307 * Handle a cancel requested from a [_StreamSubscriptionImpl]. | 307 * Handle a cancel requested from a [_StreamSubscriptionImpl]. |
308 * | 308 * |
309 * This method is called from [_StreamSubscriptionImpl.cancel]. | 309 * This method is called from [_StreamSubscriptionImpl.cancel]. |
310 * | 310 * |
311 * If an event is currently firing, the cancel is delayed | 311 * If an event is currently firing, the cancel is delayed |
312 * until after the subscribers have received the event. | 312 * until after the subscribers have received the event. |
313 * | |
314 * This will also close the stream. | |
313 */ | 315 */ |
314 void _cancel(_StreamSubscriptionImpl subscriber); | 316 void _cancel(_StreamSubscriptionImpl subscriber); |
315 | 317 |
316 /** | 318 /** |
317 * Iterate over all current subscribers and perform an action on each. | 319 * Iterate over all current subscribers and perform an action on each. |
318 * | 320 * |
319 * Subscribers added during the iteration will not be visited. | 321 * Subscribers added during the iteration will not be visited. |
320 * Subscribers unsubscribed during the iteration will only be removed | 322 * Subscribers unsubscribed during the iteration will only be removed |
321 * after they have been acted on. | 323 * after they have been acted on. |
322 * | 324 * |
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1214 onError: this._signalError, | 1216 onError: this._signalError, |
1215 onDone: this._close); | 1217 onDone: this._close); |
1216 } else { | 1218 } else { |
1217 // TODO(lrn): Check why this can happen. | 1219 // TODO(lrn): Check why this can happen. |
1218 if (_subscription == null) return; | 1220 if (_subscription == null) return; |
1219 _subscription.cancel(); | 1221 _subscription.cancel(); |
1220 _subscription = null; | 1222 _subscription = null; |
1221 } | 1223 } |
1222 } | 1224 } |
1223 } | 1225 } |
OLD | NEW |