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 "delegate/stream_subscription.dart"; | 7 import "delegate/stream_subscription.dart"; |
8 | 8 |
9 /// A [Stream] adapter for a [StreamSubscription]. | 9 /// A [Stream] adapter for a [StreamSubscription]. |
10 /// | 10 /// |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 } | 61 } |
62 | 62 |
63 /// Subscription wrapper that cancels on error. | 63 /// Subscription wrapper that cancels on error. |
64 /// | 64 /// |
65 /// Used by [SubscriptionStream] when forwarding a subscription | 65 /// Used by [SubscriptionStream] when forwarding a subscription |
66 /// created with `cancelOnError` as `true` to one with (assumed) | 66 /// created with `cancelOnError` as `true` to one with (assumed) |
67 /// `cancelOnError` as `false`. It automatically cancels the | 67 /// `cancelOnError` as `false`. It automatically cancels the |
68 /// source subscription on the first error. | 68 /// source subscription on the first error. |
69 class _CancelOnErrorSubscriptionWrapper<T> | 69 class _CancelOnErrorSubscriptionWrapper<T> |
70 extends DelegatingStreamSubscription<T> { | 70 extends DelegatingStreamSubscription<T> { |
71 _CancelOnErrorSubscriptionWrapper(StreamSubscription subscription) | 71 _CancelOnErrorSubscriptionWrapper(StreamSubscription<T> subscription) |
72 : super(subscription); | 72 : super(subscription); |
73 | 73 |
74 void onError(Function handleError) { | 74 void onError(Function handleError) { |
75 // Cancel when receiving an error. | 75 // Cancel when receiving an error. |
76 super.onError((error, StackTrace stackTrace) { | 76 super.onError((error, StackTrace stackTrace) { |
77 var cancelFuture = super.cancel(); | 77 var cancelFuture = super.cancel(); |
78 if (cancelFuture != null) { | 78 if (cancelFuture != null) { |
79 // Wait for the cancel to complete before sending the error event. | 79 // Wait for the cancel to complete before sending the error event. |
80 cancelFuture.whenComplete(() { | 80 cancelFuture.whenComplete(() { |
81 if (handleError is ZoneBinaryCallback) { | 81 if (handleError is ZoneBinaryCallback) { |
82 handleError(error, stackTrace); | 82 handleError(error, stackTrace); |
83 } else { | 83 } else { |
84 handleError(error); | 84 handleError(error); |
85 } | 85 } |
86 }); | 86 }); |
87 } else { | 87 } else { |
88 if (handleError is ZoneBinaryCallback) { | 88 if (handleError is ZoneBinaryCallback) { |
89 handleError(error, stackTrace); | 89 handleError(error, stackTrace); |
90 } else { | 90 } else { |
91 handleError(error); | 91 handleError(error); |
92 } | 92 } |
93 } | 93 } |
94 }); | 94 }); |
95 } | 95 } |
96 } | 96 } |
OLD | NEW |