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 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 * | 493 * |
494 * A new [_PendingEvents] must be generated for each listen. | 494 * A new [_PendingEvents] must be generated for each listen. |
495 */ | 495 */ |
496 _GeneratedStreamImpl(this._pending); | 496 _GeneratedStreamImpl(this._pending); |
497 | 497 |
498 StreamSubscription<T> _createSubscription(void onData(T data), | 498 StreamSubscription<T> _createSubscription(void onData(T data), |
499 Function onError, void onDone(), bool cancelOnError) { | 499 Function onError, void onDone(), bool cancelOnError) { |
500 if (_isUsed) throw new StateError("Stream has already been listened to."); | 500 if (_isUsed) throw new StateError("Stream has already been listened to."); |
501 _isUsed = true; | 501 _isUsed = true; |
502 return new _BufferingStreamSubscription<T>( | 502 return new _BufferingStreamSubscription<T>( |
503 onData, onError, onDone, cancelOnError).._setPendingEvents(_pending()); | 503 onData, onError, onDone, cancelOnError) |
| 504 .._setPendingEvents(_pending()); |
504 } | 505 } |
505 } | 506 } |
506 | 507 |
507 /** Pending events object that gets its events from an [Iterable]. */ | 508 /** Pending events object that gets its events from an [Iterable]. */ |
508 class _IterablePendingEvents<T> extends _PendingEvents<T> { | 509 class _IterablePendingEvents<T> extends _PendingEvents<T> { |
509 // The iterator providing data for data events. | 510 // The iterator providing data for data events. |
510 // Set to null when iteration has completed. | 511 // Set to null when iteration has completed. |
511 Iterator<T> _iterator; | 512 Iterator<T> _iterator; |
512 | 513 |
513 _IterablePendingEvents(Iterable<T> data) : _iterator = data.iterator; | 514 _IterablePendingEvents(Iterable<T> data) : _iterator = data.iterator; |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1041 | 1042 |
1042 /** An empty broadcast stream, sending a done event as soon as possible. */ | 1043 /** An empty broadcast stream, sending a done event as soon as possible. */ |
1043 class _EmptyStream<T> extends Stream<T> { | 1044 class _EmptyStream<T> extends Stream<T> { |
1044 const _EmptyStream() : super._internal(); | 1045 const _EmptyStream() : super._internal(); |
1045 bool get isBroadcast => true; | 1046 bool get isBroadcast => true; |
1046 StreamSubscription<T> listen(void onData(T data), | 1047 StreamSubscription<T> listen(void onData(T data), |
1047 {Function onError, void onDone(), bool cancelOnError}) { | 1048 {Function onError, void onDone(), bool cancelOnError}) { |
1048 return new _DoneStreamSubscription<T>(onDone); | 1049 return new _DoneStreamSubscription<T>(onDone); |
1049 } | 1050 } |
1050 } | 1051 } |
OLD | NEW |