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(StreamSink sink); | 10 void replay(StreamSink sink); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 Events(); | 65 Events(); |
66 Events.fromIterable(Iterable iterable) { | 66 Events.fromIterable(Iterable iterable) { |
67 for (var value in iterable) add(value); | 67 for (var value in iterable) add(value); |
68 close(); | 68 close(); |
69 } | 69 } |
70 | 70 |
71 /** Capture events from a stream into a new [Events] object. */ | 71 /** Capture events from a stream into a new [Events] object. */ |
72 factory Events.capture(Stream stream, | 72 factory Events.capture(Stream stream, |
73 { bool unsubscribeOnError: false }) = CaptureEvents; | 73 { bool unsubscribeOnError: false }) = CaptureEvents; |
74 | 74 |
75 // Sink interface. | 75 // StreamSink interface. |
76 add(var value) { events.add(new DataEvent(value)); } | 76 add(var value) { events.add(new DataEvent(value)); } |
77 | 77 |
78 void signalError(AsyncError error) { | 78 void signalError(AsyncError error) { |
79 events.add(new ErrorEvent(error)); | 79 events.add(new ErrorEvent(error)); |
80 } | 80 } |
81 | 81 |
82 void close() { | 82 void close() { |
83 events.add(const DoneEvent()); | 83 events.add(const DoneEvent()); |
84 } | 84 } |
85 | 85 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 } | 159 } |
160 | 160 |
161 void resume() { | 161 void resume() { |
162 subscription.resume(); | 162 subscription.resume(); |
163 } | 163 } |
164 | 164 |
165 void onDone(void action()) { | 165 void onDone(void action()) { |
166 onDoneSignal.future.whenComplete(action); | 166 onDoneSignal.future.whenComplete(action); |
167 } | 167 } |
168 } | 168 } |
OLD | NEW |