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

Side by Side Diff: tests/lib/async/event_helper.dart

Issue 11794043: Remove Signal class and use Future/.whenComplete instead. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Comment updated. Created 7 years, 11 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/stream_impl.dart ('k') | tests/lib/async/stream_controller_async_test.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 library event_helper; 5 library event_helper;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 class Event { 9 class Event {
10 void replay(StreamSink sink); 10 void replay(StreamSink sink);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 105 }
106 106
107 // Operations that only work when there is a subscription feeding the Events. 107 // Operations that only work when there is a subscription feeding the Events.
108 108
109 /** 109 /**
110 * Pauses the subscription that feeds this [Events]. 110 * Pauses the subscription that feeds this [Events].
111 * 111 *
112 * Should only be used when there is a subscription. That is, after a 112 * Should only be used when there is a subscription. That is, after a
113 * call to [subscribeTo]. 113 * call to [subscribeTo].
114 */ 114 */
115 void pause([Signal resumeSignal]) { 115 void pause([Future resumeSignal]) {
116 throw new StateError("Not capturing events."); 116 throw new StateError("Not capturing events.");
117 } 117 }
118 118
119 /** Resumes after a call to [pause]. */ 119 /** Resumes after a call to [pause]. */
120 void resume() { 120 void resume() {
121 throw new StateError("Not capturing events."); 121 throw new StateError("Not capturing events.");
122 } 122 }
123 123
124 /** Whether the underlying subscription has been paused. */ 124 /** Whether the underlying subscription has been paused. */
125 bool get isPaused => false; 125 bool get isPaused => false;
126 126
127 /** 127 /**
128 * Sets an action to be called when this [Events] receives a 'done' event. 128 * Sets an action to be called when this [Events] receives a 'done' event.
129 */ 129 */
130 void onDone(void action()) { 130 void onDone(void action()) {
131 throw new StateError("Not capturing events."); 131 throw new StateError("Not capturing events.");
132 } 132 }
133 } 133 }
134 134
135 class CaptureEvents extends Events { 135 class CaptureEvents extends Events {
136 StreamSubscription subscription; 136 StreamSubscription subscription;
137 SignalCompleter onDoneSignal; 137 Completer onDoneSignal;
138 bool unsubscribeOnError = false; 138 bool unsubscribeOnError = false;
139 139
140 CaptureEvents(Stream stream, 140 CaptureEvents(Stream stream,
141 { bool unsubscribeOnError: false }) 141 { bool unsubscribeOnError: false })
142 : onDoneSignal = new SignalCompleter() { 142 : onDoneSignal = new Completer() {
143 this.unsubscribeOnError = unsubscribeOnError; 143 this.unsubscribeOnError = unsubscribeOnError;
144 subscription = stream.listen(add, 144 subscription = stream.listen(add,
145 onError: signalError, 145 onError: signalError,
146 onDone: close, 146 onDone: close,
147 unsubscribeOnError: unsubscribeOnError); 147 unsubscribeOnError: unsubscribeOnError);
148 } 148 }
149 149
150 void signalError(AsyncError error) { 150 void signalError(AsyncError error) {
151 super.signalError(error); 151 super.signalError(error);
152 if (unsubscribeOnError) onDoneSignal.complete(); 152 if (unsubscribeOnError) onDoneSignal.complete(null);
153 } 153 }
154 154
155 void close() { 155 void close() {
156 super.close(); 156 super.close();
157 if (onDoneSignal != null) onDoneSignal.complete(); 157 if (onDoneSignal != null) onDoneSignal.complete(null);
158 } 158 }
159 159
160 void pause([Signal resumeSignal]) { 160 void pause([Future resumeSignal]) {
161 subscription.pause(resumeSignal); 161 subscription.pause(resumeSignal);
162 } 162 }
163 163
164 void resume() { 164 void resume() {
165 subscription.resume(); 165 subscription.resume();
166 } 166 }
167 167
168 bool get isPaused => subscription.isPaused; 168 bool get isPaused => subscription.isPaused;
169 169
170 void onDone(void action()) { 170 void onDone(void action()) {
171 onDoneSignal.signal.then(action); 171 onDoneSignal.future.whenComplete(action);
172 } 172 }
173 } 173 }
OLDNEW
« no previous file with comments | « sdk/lib/async/stream_impl.dart ('k') | tests/lib/async/stream_controller_async_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698