mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 03:56:57 +00:00
[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 <lrn@google.com> Commit-Queue: Mark Zhou <markzipan@google.com>
This commit is contained in:
parent
359023d699
commit
7bc496951e
|
@ -305,10 +305,7 @@ class _AsyncStarImpl<T> {
|
|||
// already be scheduled. This will cause at least one more iteration to
|
||||
// run (adding another data item to the Stream) before actually pausing.
|
||||
// It could be fixed by moving the `isPaused` check inside `runBody`.
|
||||
if (isScheduled ||
|
||||
controller.isPaused ||
|
||||
isSuspendedAtYieldStar ||
|
||||
isSuspendedAtAwait) {
|
||||
if (isScheduled || controller.isPaused || isSuspendedAtYieldStar) {
|
||||
return;
|
||||
}
|
||||
isScheduled = true;
|
||||
|
|
|
@ -303,10 +303,7 @@ class _AsyncStarImpl<T> {
|
|||
// already be scheduled. This will cause at least one more iteration to
|
||||
// run (adding another data item to the Stream) before actually pausing.
|
||||
// It could be fixed by moving the `isPaused` check inside `runBody`.
|
||||
if (isScheduled ||
|
||||
controller.isPaused ||
|
||||
isSuspendedAtYieldStar ||
|
||||
isSuspendedAtAwait) {
|
||||
if (isScheduled || controller.isPaused || isSuspendedAtYieldStar) {
|
||||
return;
|
||||
}
|
||||
isScheduled = true;
|
||||
|
|
33
tests/language/async_star/yield_from_catch_test.dart
Normal file
33
tests/language/async_star/yield_from_catch_test.dart
Normal file
|
@ -0,0 +1,33 @@
|
|||
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// Test for issue: https://github.com/dart-lang/sdk/issues/39994
|
||||
|
||||
import "dart:async";
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
|
||||
Stream<String> testStream() async* {
|
||||
try {
|
||||
await testThrow();
|
||||
yield "A";
|
||||
} catch (e) {
|
||||
yield "B";
|
||||
yield "C";
|
||||
yield "D";
|
||||
}
|
||||
}
|
||||
|
||||
testThrow() async {
|
||||
throw Exception();
|
||||
}
|
||||
|
||||
test() async {
|
||||
var result = await testStream().toList();
|
||||
Expect.listEquals(["B", "C", "D"], result);
|
||||
}
|
||||
|
||||
main() {
|
||||
asyncTest(test);
|
||||
}
|
33
tests/language_2/async_star/yield_from_catch_test.dart
Normal file
33
tests/language_2/async_star/yield_from_catch_test.dart
Normal file
|
@ -0,0 +1,33 @@
|
|||
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// Test for issue: https://github.com/dart-lang/sdk/issues/39994
|
||||
|
||||
import "dart:async";
|
||||
import "package:expect/expect.dart";
|
||||
import "package:async_helper/async_helper.dart";
|
||||
|
||||
Stream<String> testStream() async* {
|
||||
try {
|
||||
await testThrow();
|
||||
yield "A";
|
||||
} catch (e) {
|
||||
yield "B";
|
||||
yield "C";
|
||||
yield "D";
|
||||
}
|
||||
}
|
||||
|
||||
testThrow() async {
|
||||
throw Exception();
|
||||
}
|
||||
|
||||
test() async {
|
||||
var result = await testStream().toList();
|
||||
Expect.listEquals(["B", "C", "D"], result);
|
||||
}
|
||||
|
||||
main() {
|
||||
asyncTest(test);
|
||||
}
|
Loading…
Reference in a new issue