| 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 library event_helper; | 5 library event_helper; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 class Event { | 9 abstract class Event { |
| 10 void replay(StreamSink sink); | 10 void replay(StreamSink sink); |
| 11 } | 11 } |
| 12 | 12 |
| 13 class DataEvent implements Event { | 13 class DataEvent implements Event { |
| 14 final data; | 14 final data; |
| 15 | 15 |
| 16 DataEvent(this.data); | 16 DataEvent(this.data); |
| 17 | 17 |
| 18 void replay(StreamSink sink) { sink.add(data); } | 18 void replay(StreamSink sink) { sink.add(data); } |
| 19 | 19 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 */ | 114 */ |
| 115 void pause([Future 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. */ | |
| 125 bool get isPaused => false; | |
| 126 | |
| 127 /** | 124 /** |
| 128 * Sets an action to be called when this [Events] receives a 'done' event. | 125 * Sets an action to be called when this [Events] receives a 'done' event. |
| 129 */ | 126 */ |
| 130 void onDone(void action()) { | 127 void onDone(void action()) { |
| 131 throw new StateError("Not capturing events."); | 128 throw new StateError("Not capturing events."); |
| 132 } | 129 } |
| 133 } | 130 } |
| 134 | 131 |
| 135 class CaptureEvents extends Events { | 132 class CaptureEvents extends Events { |
| 136 StreamSubscription subscription; | 133 StreamSubscription subscription; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 158 } | 155 } |
| 159 | 156 |
| 160 void pause([Future resumeSignal]) { | 157 void pause([Future resumeSignal]) { |
| 161 subscription.pause(resumeSignal); | 158 subscription.pause(resumeSignal); |
| 162 } | 159 } |
| 163 | 160 |
| 164 void resume() { | 161 void resume() { |
| 165 subscription.resume(); | 162 subscription.resume(); |
| 166 } | 163 } |
| 167 | 164 |
| 168 bool get isPaused => subscription.isPaused; | |
| 169 | |
| 170 void onDone(void action()) { | 165 void onDone(void action()) { |
| 171 onDoneSignal.future.whenComplete(action); | 166 onDoneSignal.future.whenComplete(action); |
| 172 } | 167 } |
| 173 } | 168 } |
| OLD | NEW |