dart-sdk/sdk/lib/async
Lasse R.H. Nielsen e86b08e5bb Forwards ignore bit to chained-to _Future.
If a target `_Future` is chained to another source `_Future`,
then it's because the target will complete with the same
result as the source future. Instead of keeping both
alive with a listener on the source which completes the target,
instead the target moves all its listeners to be directly on
the source, and keeps a link to the source in case more listeners
are added later.
The idea is that most futures are unreferenced after they have
had their first listener, so the target future has a chance
to be GC'ed.

If the target future has `.ignore()` called, and has no listener,
then the source completing with an error should not cause the
error to be uncaught. Without the optimization, the source would
have had a listener, and the target would ignore the error.

To simulate that, the source now gets a copy of the target's
`_ignoreUnhandledErrors` flag.

This is still not precisely the same as it would be without the
optimization. If *two* target futures are chained to the same source,
and only one of targes has `.ignore()` called, then this
implementation will make the uncaught error not be reported,
where it technically should.

(An alternative would be to *not* use chaining for futures
with `ignore()` called on them. But those are precisely futures
that are likely to be GC'able, because someone has already said
that they don't care if the future complete with errors.)

Fixes #54943

Bug: https://github.com/dart-lang/sdk/issues/54943
Change-Id: I0dbb4919ce2ea612d66539862fa0eb188aab8287
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352908
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2024-02-21 13:05:56 +00:00
..
async.dart Add record-related wait extensions on Future tuples. 2023-04-04 11:39:49 +00:00
async_error.dart Add class modifiers to dart:async. 2023-03-20 12:12:46 +00:00
async_sources.gni Add record-related wait extensions on Future tuples. 2023-04-04 11:39:49 +00:00
broadcast_stream_controller.dart feat: add missing generic type to Stream.close 2024-01-15 17:00:43 +00:00
deferred_load.dart Add class modifiers to dart:async. 2023-03-20 12:12:46 +00:00
future.dart Avoid type checks in Future.wait 2024-02-13 16:07:12 +00:00
future_extensions.dart Add record-related wait extensions on Future tuples. 2023-04-04 11:39:49 +00:00
future_impl.dart Forwards ignore bit to chained-to _Future. 2024-02-21 13:05:56 +00:00
schedule_microtask.dart Add back accidentally removed pragma on scheduleMicrotask. 2021-02-04 19:28:37 +00:00
stream.dart [doc/async] Change Stream.asyncMap doc according to the current behavior 2023-12-12 11:10:55 +00:00
stream_controller.dart [vm] Improve asynchronous unwinding through Stream methods 2024-02-15 23:00:44 +00:00
stream_impl.dart [vm] Improve asynchronous unwinding through Stream methods 2024-02-15 23:00:44 +00:00
stream_pipe.dart Revert "Make nullFuture be per-zone." 2022-06-24 14:13:39 +00:00
stream_transformers.dart
timer.dart [doc/async] Remove excessive statement from Timer.periodic() documentation 2024-01-09 09:10:44 +00:00
zone.dart [vm] Rework awaiter stack unwinding. 2023-06-30 14:03:03 +00:00