Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Side by Side Diff: lib/src/subscription_stream.dart

Issue 1870543004: Add typed wrapper functions to delegate classes. (Closed) Base URL: git@github.com:dart-lang/async.git@master
Patch Set: Code review changes Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698