Skip to content

Commit 7bc4969

Browse files
Markzipancommit-bot@chromium.org
authored andcommitted
[dartdevc] Fixing issue whereby async generators would not resume properly after yielding from within a catch block.
Presubmits at cl/297164263 Fixes #39994 Change-Id: I2fff5db716f1b3e4f125ec9ae5f018a7edbbed67 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136846 Reviewed-by: Lasse R.H. Nielsen <[email protected]> Commit-Queue: Mark Zhou <[email protected]>
1 parent 359023d commit 7bc4969

File tree

4 files changed

+68
-8
lines changed

4 files changed

+68
-8
lines changed

sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,7 @@ class _AsyncStarImpl<T> {
305305
// already be scheduled. This will cause at least one more iteration to
306306
// run (adding another data item to the Stream) before actually pausing.
307307
// It could be fixed by moving the `isPaused` check inside `runBody`.
308-
if (isScheduled ||
309-
controller.isPaused ||
310-
isSuspendedAtYieldStar ||
311-
isSuspendedAtAwait) {
308+
if (isScheduled || controller.isPaused || isSuspendedAtYieldStar) {
312309
return;
313310
}
314311
isScheduled = true;

sdk_nnbd/lib/_internal/js_dev_runtime/patch/async_patch.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,7 @@ class _AsyncStarImpl<T> {
303303
// already be scheduled. This will cause at least one more iteration to
304304
// run (adding another data item to the Stream) before actually pausing.
305305
// It could be fixed by moving the `isPaused` check inside `runBody`.
306-
if (isScheduled ||
307-
controller.isPaused ||
308-
isSuspendedAtYieldStar ||
309-
isSuspendedAtAwait) {
306+
if (isScheduled || controller.isPaused || isSuspendedAtYieldStar) {
310307
return;
311308
}
312309
isScheduled = true;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
// Test for issue: https://github.com/dart-lang/sdk/issues/39994
6+
7+
import "dart:async";
8+
import "package:expect/expect.dart";
9+
import "package:async_helper/async_helper.dart";
10+
11+
Stream<String> testStream() async* {
12+
try {
13+
await testThrow();
14+
yield "A";
15+
} catch (e) {
16+
yield "B";
17+
yield "C";
18+
yield "D";
19+
}
20+
}
21+
22+
testThrow() async {
23+
throw Exception();
24+
}
25+
26+
test() async {
27+
var result = await testStream().toList();
28+
Expect.listEquals(["B", "C", "D"], result);
29+
}
30+
31+
main() {
32+
asyncTest(test);
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
// Test for issue: https://github.com/dart-lang/sdk/issues/39994
6+
7+
import "dart:async";
8+
import "package:expect/expect.dart";
9+
import "package:async_helper/async_helper.dart";
10+
11+
Stream<String> testStream() async* {
12+
try {
13+
await testThrow();
14+
yield "A";
15+
} catch (e) {
16+
yield "B";
17+
yield "C";
18+
yield "D";
19+
}
20+
}
21+
22+
testThrow() async {
23+
throw Exception();
24+
}
25+
26+
test() async {
27+
var result = await testStream().toList();
28+
Expect.listEquals(["B", "C", "D"], result);
29+
}
30+
31+
main() {
32+
asyncTest(test);
33+
}

0 commit comments

Comments
 (0)