Skip to content

Commit ddb2d96

Browse files
committed
test added. formatted.
1 parent 468b80f commit ddb2d96

File tree

2 files changed

+84
-4
lines changed

2 files changed

+84
-4
lines changed

pkgs/async/lib/src/subscription_stream.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,20 @@ class _CancelOnErrorSubscriptionWrapper<T>
7676
super.onError((Object error, StackTrace stackTrace) {
7777
// Wait for the cancel to complete before sending the error event.
7878
super.cancel().whenComplete(() {
79-
if (handleError is ZoneBinaryCallback<void, Object, StackTrace> || handleError is ZoneBinaryCallback) {
80-
handleError?.call(error, stackTrace);
81-
} else if (handleError is ZoneUnaryCallback<void, Object> || handleError is ZoneUnaryCallback) {
82-
handleError?.call(error);
79+
if (handleError is ZoneBinaryCallback<void, Object, StackTrace>) {
80+
handleError(error, stackTrace);
81+
} else if (handleError is ZoneBinaryCallback) {
82+
handleError(error, stackTrace);
83+
} else if (handleError is ZoneUnaryCallback<void, Object>) {
84+
handleError(error);
85+
} else if (handleError is ZoneUnaryCallback) {
86+
handleError(error);
8387
}
8488
});
8589
});
8690
}
8791
}
92+
93+
abstract class BinaryWrapper {
94+
void binaryCall<T1, T2>(T1 t1, T2 t2);
95+
}

pkgs/async/test/subscription_stream_test.dart

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,80 @@ void main() {
148148
});
149149
}
150150
});
151+
152+
group('subscriptionStream error callback', () {
153+
test('- binary typed', () async {
154+
var completer = Completer<void>();
155+
var stream = createErrorStream();
156+
var sourceSubscription = stream.listen(null, cancelOnError: true);
157+
var subscriptionStream = SubscriptionStream(sourceSubscription);
158+
159+
void f(Object error, StackTrace stackTrace) {
160+
completer.complete();
161+
}
162+
163+
subscriptionStream.listen((_) {},
164+
onError: f,
165+
onDone: () => throw 'should not happen',
166+
cancelOnError: true);
167+
await completer.future;
168+
await flushMicrotasks();
169+
});
170+
171+
test('- binary dynamic', () async {
172+
var completer = Completer<void>();
173+
var stream = createErrorStream();
174+
var sourceSubscription = stream.listen(null, cancelOnError: true);
175+
var subscriptionStream = SubscriptionStream(sourceSubscription);
176+
177+
subscriptionStream.listen((_) {},
178+
onError: (error, stackTrace) {
179+
completer.complete();
180+
},
181+
onDone: () => throw 'should not happen',
182+
cancelOnError: true);
183+
await completer.future;
184+
await flushMicrotasks();
185+
});
186+
187+
test('- unary typed', () async {
188+
var completer = Completer<void>();
189+
var stream = createErrorStream();
190+
var sourceSubscription = stream.listen(null, cancelOnError: true);
191+
var subscriptionStream = SubscriptionStream(sourceSubscription);
192+
193+
void f(Object error) {
194+
completer.complete();
195+
}
196+
197+
subscriptionStream.listen((_) {},
198+
onError: f,
199+
onDone: () => throw 'should not happen',
200+
cancelOnError: true);
201+
await completer.future;
202+
await flushMicrotasks();
203+
});
204+
205+
test('- unary dynamic', () async {
206+
var completer = Completer<void>();
207+
var stream = createErrorStream();
208+
var sourceSubscription = stream.listen(null, cancelOnError: true);
209+
var subscriptionStream = SubscriptionStream(sourceSubscription);
210+
211+
subscriptionStream.listen((_) {},
212+
onError: (error) {
213+
completer.complete();
214+
},
215+
onDone: () => throw 'should not happen',
216+
cancelOnError: true);
217+
await completer.future;
218+
await flushMicrotasks();
219+
});
220+
});
151221
}
152222

223+
typedef BinaryFunc = void Function(Object s, StackTrace tr);
224+
153225
Stream<int> createStream() async* {
154226
yield 1;
155227
await flushMicrotasks();

0 commit comments

Comments
 (0)