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

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

Issue 12213092: Rework Timer interface. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 10 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
« no previous file with comments | « sdk/lib/async/future_impl.dart ('k') | sdk/lib/async/timer.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // 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 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 * due to a second event in the current cycle, the timer is canceled again. 1019 * due to a second event in the current cycle, the timer is canceled again.
1020 */ 1020 */
1021 Timer scheduleTimer = null; 1021 Timer scheduleTimer = null;
1022 1022
1023 bool get isEmpty; 1023 bool get isEmpty;
1024 1024
1025 bool get isScheduled => scheduleTimer != null; 1025 bool get isScheduled => scheduleTimer != null;
1026 1026
1027 void schedule(_StreamImpl stream) { 1027 void schedule(_StreamImpl stream) {
1028 if (isScheduled) return; 1028 if (isScheduled) return;
1029 scheduleTimer = new Timer(0, (_) { 1029 scheduleTimer = Timer.run(() {
1030 scheduleTimer = null; 1030 scheduleTimer = null;
1031 stream._handlePendingEvents(); 1031 stream._handlePendingEvents();
1032 }); 1032 });
1033 } 1033 }
1034 1034
1035 void cancelSchedule() { 1035 void cancelSchedule() {
1036 assert(isScheduled); 1036 assert(isScheduled);
1037 scheduleTimer.cancel(); 1037 scheduleTimer.cancel();
1038 scheduleTimer = null; 1038 scheduleTimer = null;
1039 } 1039 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 _DoneHandler _handler; 1077 _DoneHandler _handler;
1078 Timer _timer; 1078 Timer _timer;
1079 int _pauseCount = 0; 1079 int _pauseCount = 0;
1080 1080
1081 _DoneSubscription(this._handler) { 1081 _DoneSubscription(this._handler) {
1082 _delayDone(); 1082 _delayDone();
1083 } 1083 }
1084 1084
1085 void _delayDone() { 1085 void _delayDone() {
1086 assert(_timer == null && _pauseCount == 0); 1086 assert(_timer == null && _pauseCount == 0);
1087 _timer = new Timer(0, (_) { 1087 _timer = Timer.run(() {
1088 if (_handler != null) _handler(); 1088 if (_handler != null) _handler();
1089 }); 1089 });
1090 } 1090 }
1091 1091
1092 bool get _isComplete => _timer == null && _pauseCount == 0; 1092 bool get _isComplete => _timer == null && _pauseCount == 0;
1093 1093
1094 void onData(void handleAction(T value)) {} 1094 void onData(void handleAction(T value)) {}
1095 1095
1096 void onError(void handleError(AsyncError error)) {} 1096 void onError(void handleError(AsyncError error)) {}
1097 1097
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 onError: this._signalError, 1161 onError: this._signalError,
1162 onDone: this._close); 1162 onDone: this._close);
1163 } else { 1163 } else {
1164 // TODO(lrn): Check why this can happen. 1164 // TODO(lrn): Check why this can happen.
1165 if (_subscription == null) return; 1165 if (_subscription == null) return;
1166 _subscription.cancel(); 1166 _subscription.cancel();
1167 _subscription = null; 1167 _subscription = null;
1168 } 1168 }
1169 } 1169 }
1170 } 1170 }
OLDNEW
« no previous file with comments | « sdk/lib/async/future_impl.dart ('k') | sdk/lib/async/timer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698