| 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 /** Abstract and private interface for a place to put events. */ | 7 /** Abstract and private interface for a place to put events. */ |
| 8 abstract class _EventSink<T> { | 8 abstract class _EventSink<T> { |
| 9 void _add(T data); | 9 void _add(T data); |
| 10 void _addError(Object error, StackTrace stackTrace); | 10 void _addError(Object error, StackTrace stackTrace); |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 | 481 |
| 482 /** Hook called when the subscription has been created. */ | 482 /** Hook called when the subscription has been created. */ |
| 483 void _onListen(StreamSubscription subscription) {} | 483 void _onListen(StreamSubscription subscription) {} |
| 484 } | 484 } |
| 485 | 485 |
| 486 typedef _PendingEvents _EventGenerator(); | 486 typedef _PendingEvents _EventGenerator(); |
| 487 | 487 |
| 488 /** Stream that generates its own events. */ | 488 /** Stream that generates its own events. */ |
| 489 class _GeneratedStreamImpl<T> extends _StreamImpl<T> { | 489 class _GeneratedStreamImpl<T> extends _StreamImpl<T> { |
| 490 final _EventGenerator _pending; | 490 final _EventGenerator _pending; |
| 491 bool _isUsed = false; |
| 491 /** | 492 /** |
| 492 * Initializes the stream to have only the events provided by a | 493 * Initializes the stream to have only the events provided by a |
| 493 * [_PendingEvents]. | 494 * [_PendingEvents]. |
| 494 * | 495 * |
| 495 * A new [_PendingEvents] must be generated for each listen. | 496 * A new [_PendingEvents] must be generated for each listen. |
| 496 */ | 497 */ |
| 497 _GeneratedStreamImpl(this._pending); | 498 _GeneratedStreamImpl(this._pending); |
| 498 | 499 |
| 499 StreamSubscription _createSubscription(bool cancelOnError) { | 500 StreamSubscription _createSubscription(bool cancelOnError) { |
| 501 if (_isUsed) throw new StateError("Stream has already been listened to."); |
| 502 _isUsed = true; |
| 500 _BufferingStreamSubscription<T> subscription = | 503 _BufferingStreamSubscription<T> subscription = |
| 501 new _BufferingStreamSubscription(cancelOnError); | 504 new _BufferingStreamSubscription(cancelOnError); |
| 502 subscription._setPendingEvents(_pending()); | 505 subscription._setPendingEvents(_pending()); |
| 503 return subscription; | 506 return subscription; |
| 504 } | 507 } |
| 505 } | 508 } |
| 506 | 509 |
| 507 | 510 |
| 508 /** Pending events object that gets its events from an [Iterable]. */ | 511 /** Pending events object that gets its events from an [Iterable]. */ |
| 509 class _IterablePendingEvents<T> extends _PendingEvents { | 512 class _IterablePendingEvents<T> extends _PendingEvents { |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 _Future<bool> hasNext = _futureOrPrefetch; | 1028 _Future<bool> hasNext = _futureOrPrefetch; |
| 1026 _clear(); | 1029 _clear(); |
| 1027 hasNext._complete(false); | 1030 hasNext._complete(false); |
| 1028 return; | 1031 return; |
| 1029 } | 1032 } |
| 1030 _subscription.pause(); | 1033 _subscription.pause(); |
| 1031 _futureOrPrefetch = null; | 1034 _futureOrPrefetch = null; |
| 1032 _state = _STATE_EXTRA_DONE; | 1035 _state = _STATE_EXTRA_DONE; |
| 1033 } | 1036 } |
| 1034 } | 1037 } |
| OLD | NEW |