| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import '../typed/stream_subscription.dart'; |
| 8 |
| 7 /// Simple delegating wrapper around a [StreamSubscription]. | 9 /// Simple delegating wrapper around a [StreamSubscription]. |
| 8 /// | 10 /// |
| 9 /// Subclasses can override individual methods. | 11 /// Subclasses can override individual methods. |
| 10 class DelegatingStreamSubscription<T> implements StreamSubscription<T> { | 12 class DelegatingStreamSubscription<T> implements StreamSubscription<T> { |
| 11 final StreamSubscription _source; | 13 final StreamSubscription _source; |
| 12 | 14 |
| 13 /// Create delegating subscription forwarding calls to [sourceSubscription]. | 15 /// Create delegating subscription forwarding calls to [sourceSubscription]. |
| 14 DelegatingStreamSubscription(StreamSubscription sourceSubscription) | 16 DelegatingStreamSubscription(StreamSubscription<T> sourceSubscription) |
| 15 : _source = sourceSubscription; | 17 : _source = sourceSubscription; |
| 16 | 18 |
| 19 /// Creates a wrapper that asserts the types of the values emitted by |
| 20 /// [subscription]. |
| 21 /// |
| 22 /// This soundly converts a [StreamSubscription] without a generic type to a |
| 23 /// `StreamSubscription<T>` by asserting that its events are instances of `T` |
| 24 /// whenever they're accessed. If they're not, it throws a [CastError]. |
| 25 static StreamSubscription/*<T>*/ typed/*<T>*/( |
| 26 StreamSubscription subscription) => |
| 27 subscription is StreamSubscription/*<T>*/ |
| 28 ? subscription |
| 29 : new TypeSafeStreamSubscription/*<T>*/(subscription); |
| 30 |
| 17 void onData(void handleData(T data)) { | 31 void onData(void handleData(T data)) { |
| 18 _source.onData(handleData); | 32 _source.onData(handleData); |
| 19 } | 33 } |
| 20 | 34 |
| 21 void onError(Function handleError) { | 35 void onError(Function handleError) { |
| 22 _source.onError(handleError); | 36 _source.onError(handleError); |
| 23 } | 37 } |
| 24 | 38 |
| 25 void onDone(void handleDone()) { | 39 void onDone(void handleDone()) { |
| 26 _source.onDone(handleDone); | 40 _source.onDone(handleDone); |
| 27 } | 41 } |
| 28 | 42 |
| 29 void pause([Future resumeFuture]) { | 43 void pause([Future resumeFuture]) { |
| 30 _source.pause(resumeFuture); | 44 _source.pause(resumeFuture); |
| 31 } | 45 } |
| 32 | 46 |
| 33 void resume() { | 47 void resume() { |
| 34 _source.resume(); | 48 _source.resume(); |
| 35 } | 49 } |
| 36 | 50 |
| 37 Future cancel() => _source.cancel(); | 51 Future cancel() => _source.cancel(); |
| 38 | 52 |
| 39 Future asFuture([futureValue]) => _source.asFuture(futureValue); | 53 Future asFuture([futureValue]) => _source.asFuture(futureValue); |
| 40 | 54 |
| 41 bool get isPaused => _source.isPaused; | 55 bool get isPaused => _source.isPaused; |
| 42 } | 56 } |
| OLD | NEW |