Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Side by Side Diff: sdk/lib/async/stream_impl.dart

Issue 16240008: Make StreamController be a StreamSink, not just an EventSink. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Complete rewrite. StreamController is now itself a StreamSink. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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); 10 void _addError(Object error);
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 void onDone(), 712 void onDone(),
713 bool cancelOnError}) { 713 bool cancelOnError}) {
714 if (_controller == null) { 714 if (_controller == null) {
715 throw new StateError("Source stream has been closed."); 715 throw new StateError("Source stream has been closed.");
716 } 716 }
717 if (_subscription == null) { 717 if (_subscription == null) {
718 _subscription = _source.listen(_controller.add, 718 _subscription = _source.listen(_controller.add,
719 onError: _controller.addError, 719 onError: _controller.addError,
720 onDone: _controller.close); 720 onDone: _controller.close);
721 } 721 }
722 return _controller.stream.listen(onData, onError: onError, onDone: onDone, 722 if (onData == null) onData = _nullDataHandler;
723 cancelOnError: cancelOnError); 723 if (onError == null) onError = _nullErrorHandler;
724 if (onDone == null) onDone = _nullDoneHandler;
725 cancelOnError = identical(true, cancelOnError);
726 return _controller._subscribe(onData, onError, onDone, cancelOnError);
724 } 727 }
725 728
726 void _onCancel() { 729 void _onCancel() {
727 // Called by [_controller] when it has no subscribers left. 730 // Called by [_controller] when it has no subscribers left.
728 StreamSubscription subscription = _subscription; 731 StreamSubscription subscription = _subscription;
729 _subscription = null; 732 _subscription = null;
730 _controller = null; // Marks the stream as no longer listenable. 733 _controller = null; // Marks the stream as no longer listenable.
731 subscription.cancel(); 734 subscription.cancel();
732 } 735 }
733 } 736 }
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 _FutureImpl<bool> hasNext = _futureOrPrefetch; 878 _FutureImpl<bool> hasNext = _futureOrPrefetch;
876 _clear(); 879 _clear();
877 hasNext._setValue(false); 880 hasNext._setValue(false);
878 return; 881 return;
879 } 882 }
880 _subscription.pause(); 883 _subscription.pause();
881 _futureOrPrefetch = null; 884 _futureOrPrefetch = null;
882 _state = _STATE_EXTRA_DONE; 885 _state = _STATE_EXTRA_DONE;
883 } 886 }
884 } 887 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698