| 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); |
| 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(EventSink sink) { sink.add(data); } | 18 void replay(EventSink sink) { sink.add(data); } |
| 19 | 19 |
| 20 int get hashCode => data.hashCode; | 20 int get hashCode => data.hashCode; |
| 21 | 21 |
| 22 bool operator==(Object other) { | 22 bool operator==(Object other) { |
| 23 if (other is! DataEvent) return false; | 23 if (other is! DataEvent) return false; |
| 24 DataEvent otherEvent = other; | 24 DataEvent otherEvent = other; |
| 25 return data == other.data; | 25 return data == otherEvent.data; |
| 26 } | 26 } |
| 27 | 27 |
| 28 String toString() => "DataEvent: $data"; | 28 String toString() => "DataEvent: $data"; |
| 29 } | 29 } |
| 30 | 30 |
| 31 class ErrorEvent implements Event { | 31 class ErrorEvent implements Event { |
| 32 final error; | 32 final error; |
| 33 | 33 |
| 34 ErrorEvent(this.error); | 34 ErrorEvent(this.error); |
| 35 | 35 |
| 36 void replay(EventSink sink) { sink.addError(error); } | 36 void replay(EventSink sink) { sink.addError(error); } |
| 37 | 37 |
| 38 int get hashCode => error.error.hashCode; | 38 int get hashCode => error.error.hashCode; |
| 39 | 39 |
| 40 bool operator==(Object other) { | 40 bool operator==(Object other) { |
| 41 if (other is! ErrorEvent) return false; | 41 if (other is! ErrorEvent) return false; |
| 42 ErrorEvent otherEvent = other; | 42 ErrorEvent otherEvent = other; |
| 43 return error == other.error; | 43 return error == otherEvent.error; |
| 44 } | 44 } |
| 45 | 45 |
| 46 String toString() => "ErrorEvent: ${error}"; | 46 String toString() => "ErrorEvent: ${error}"; |
| 47 } | 47 } |
| 48 | 48 |
| 49 class DoneEvent implements Event { | 49 class DoneEvent implements Event { |
| 50 const DoneEvent(); | 50 const DoneEvent(); |
| 51 | 51 |
| 52 void replay(EventSink sink) { sink.close(); } | 52 void replay(EventSink sink) { sink.close(); } |
| 53 | 53 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 void resume() { | 169 void resume() { |
| 170 if (trace) print("Events#$hashCode: resume"); | 170 if (trace) print("Events#$hashCode: resume"); |
| 171 subscription.resume(); | 171 subscription.resume(); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void onDone(void action()) { | 174 void onDone(void action()) { |
| 175 if (trace) print("Events#$hashCode: onDone"); | 175 if (trace) print("Events#$hashCode: onDone"); |
| 176 onDoneSignal.future.whenComplete(action); | 176 onDoneSignal.future.whenComplete(action); |
| 177 } | 177 } |
| 178 } | 178 } |
| OLD | NEW |