| 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 abstract class Event { | 9 abstract class Event { |
| 10 void replay(EventSink sink); | 10 void replay(EventSink sink); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 151 |
| 152 CaptureEvents(Stream stream, | 152 CaptureEvents(Stream stream, |
| 153 { bool cancelOnError: false }) { | 153 { bool cancelOnError: false }) { |
| 154 this.cancelOnError = cancelOnError; | 154 this.cancelOnError = cancelOnError; |
| 155 subscription = stream.listen(add, | 155 subscription = stream.listen(add, |
| 156 onError: addError, | 156 onError: addError, |
| 157 onDone: close, | 157 onDone: close, |
| 158 cancelOnError: cancelOnError); | 158 cancelOnError: cancelOnError); |
| 159 } | 159 } |
| 160 | 160 |
| 161 void addError(error) { | 161 void addError(error, [stackTrace]) { |
| 162 super.addError(error); | 162 super.addError(error, stackTrace); |
| 163 if (cancelOnError) { | 163 if (cancelOnError) { |
| 164 onDoneSignal.complete(); | 164 onDoneSignal.complete(); |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 | 167 |
| 168 void pause([Future resumeSignal]) { | 168 void pause([Future resumeSignal]) { |
| 169 if (trace) print("Events#$hashCode: pause"); | 169 if (trace) print("Events#$hashCode: pause"); |
| 170 subscription.pause(resumeSignal); | 170 subscription.pause(resumeSignal); |
| 171 } | 171 } |
| 172 | 172 |
| 173 void resume() { | 173 void resume() { |
| 174 if (trace) print("Events#$hashCode: resume"); | 174 if (trace) print("Events#$hashCode: resume"); |
| 175 subscription.resume(); | 175 subscription.resume(); |
| 176 } | 176 } |
| 177 | 177 |
| 178 void onDone(void action()) { | 178 void onDone(void action()) { |
| 179 if (trace) print("Events#$hashCode: onDone"); | 179 if (trace) print("Events#$hashCode: onDone"); |
| 180 super.onDone(action); | 180 super.onDone(action); |
| 181 } | 181 } |
| 182 } | 182 } |
| OLD | NEW |