-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue 56806, incorrect ignore on futures.
Makes `whenComplete` create a new future with either the result of the original, or the error of a future returned by the callback. Until now it was returning the original future, causing it to be chained after it was completed. That caused issue with `ignore()`. (Which suggests that there is still something iffy about ignore and chaining.) Combines `chainCoreFuture{Sync,Async}` into one function with boolean flag. Most of the code is the same, and they had accidentally drifted apart. Fixes #56806. CoreLibraryReviewExempt: Should be simple refactoring. Tested: Regression test added Bug: http://dartbug.com/56806 Change-Id: I52751c078a4e26a10e9da0a64460e2c5c7f34ae5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387360 Commit-Queue: Lasse Nielsen <[email protected]> Reviewed-by: Nate Bosch <[email protected]> Reviewed-by: Martin Kustermann <[email protected]>
- Loading branch information
Showing
4 changed files
with
111 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) 2024, 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. | ||
|
||
import "dart:async"; | ||
|
||
import 'package:async_helper/async_helper.dart'; | ||
import "package:expect/expect.dart"; | ||
|
||
// Regression test for http://dartbug.com/56806 | ||
// | ||
// Checks that `.ignore()` gets propagated correctly when chaining futures. | ||
|
||
void main() async { | ||
asyncStart(); | ||
|
||
await testNoThrow(); | ||
|
||
asyncStart(); | ||
await runZoned(testDoThrow, zoneSpecification: ZoneSpecification( | ||
handleUncaughtError: (s, p, z, Object error, StackTrace stack) { | ||
asyncEnd(); | ||
})); | ||
|
||
asyncEnd(); | ||
} | ||
|
||
Future<void> testNoThrow() async { | ||
var completer = Completer<void>(); | ||
final future = Future<void>.delayed( | ||
Duration.zero, () => throw StateError("Should be ignored")); | ||
var future2 = future.whenComplete(() async { | ||
await Future.delayed(Duration.zero); | ||
completer.complete(); | ||
}); | ||
future2.ignore(); // Has no listeners. | ||
await completer.future; | ||
} | ||
|
||
Future<void> testDoThrow() async { | ||
var completer = Completer<void>(); | ||
final future = Future<void>.delayed( | ||
Duration.zero, () => throw StateError("Should not be ignored")); | ||
future.ignore(); // Ignores error only on `future`. | ||
future.whenComplete(() async { | ||
await Future.delayed(Duration.zero); | ||
completer.complete(); | ||
}); // Should rethrow the error, as uncaught. | ||
await completer.future; | ||
} |