Previously, when completing a future with another future,
we always chained to the other future. This effectively awaits
the latter future and then completes the former with its result.
This is incorrect behavior if the former future is, say,
a `Future<Future<int>>` and the latter is a `Future<int>`.
In that case we *must not* await the latter future
because we can't complete the former future with an `int`.
We should just complete the future directly with the latter future
as a value.
We now check first whether to chain a `Future<T>` to another
future, and only does so if the latter future is a `Future<T>`
(or it's not a `T`, which shouldn't happen,
but currently does in some places).
Add test for behavior.
Change-Id: I57e27111c2fc7b7792dcf4ae9b7c1d5d504d0c0f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/53602
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
A combination of `runZoned` and `runZonedGuarded` where only the latter allows an `onError` parameter,
and only that has a nullable return type.
Retains the `onError` parameter on `runZoned` for now because it's too breaking to remove it until packages have been migrated off of it.
It will be removed in a follow-up CL.
Change-Id: If0e86c8d14e13fa089c66f4af975aeacb2616cf6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/137302
Reviewed-by: Jake Macdonald <jakemac@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
This block felt trickier than others, mostly due to random errors that I
wasn't able to find a cause for. Tests that I'm uncertain about are:
-first_regression_test
-future_timeout_test
-future_or_bad_type_test/implements
These all have status entries to prevent failures, but I think these
tests need another set of eyes.
BUG=
R=rnystrom@google.com
Review-Url: https://codereview.chromium.org/2999943002 .
When the computation passed to Future.sync returns a Future of the correct type,
then it's returned directly instead of wrapping it again.
(Until strong mode, we have an extra case for when it returns a Future of an
incorrect type, but that will eventually be removed).
This should improve the performance of Future.sync a bit.
Also adds missing Zone intercept for when the Future.sync computation throws.
Updates documentation for Future.doWhile.
Fixes#29202
BUG= http://dartbug.com/29202R=floitsch@google.com
Review-Url: https://codereview.chromium.org/2790663003 .
Update all tests
Support //# multitests for better dartfmt compatibility and fewer multitest false positives
All files under tests were manually updated with
find . -iregex '.*\.dart$' -print0 | xargs -0 perl -pi -e 's/(\S\s+)\/\/\/ /$1\/\/# /'
For now both old and new styles are allowed to accommodate CO19 tests.
R=efortuna@google.com
BUG=
Review-Url: https://codereview.chromium.org/2765693002 .
Review-Url: https://codereview.chromium.org/2765893003 .
Support //# multitests for better dartfmt compatibility and fewer multitest false positives
All files under tests were manually updated with
find . -iregex '.*\.dart$' -print0 | xargs -0 perl -pi -e 's/(\S\s+)\/\/\/ /$1\/\/# /'
For now both old and new styles are allowed to accommodate CO19 tests.
R=efortuna@google.com
Review-Url: https://codereview.chromium.org/2765693002 .
If the foreign future completes with a future, the following call to
_Future._completeWithValue would hit an assert in checked mode
(value is! Future). This change makes the _Future._completeWithValue flatten
incoming nesting futures before completing the _Future, ensuring that a
_Future never has a Future as value.
An alternative is to throw if the value of a future is another future.
That's what the assert does in checked mode, but we shouldn't be able to hit
an assert.
R=floitsch@google.com
Review URL: https://codereview.chromium.org/1966523003 .
Also treat null errors comming out of Zone.errorCallback as
NullThrownError.
This should prevent, as was always the intention, any async error
from having a null value.
This is important for async/await syntax, where the distinction
between sync and async errors is removed.
(For Dart 2.0, we could just make null throwable).
R=sgjesse@google.com
Review URL: https://codereview.chromium.org//598993002
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@40673 260f80e4-7a28-3924-810f-c04153c831b5
A chained future is one that will give exactly the same result as another
future. It is used to handle, e.g., futures returned by .then handlers.
Currently we chaing futures by simply making the future itself a listener
on the future it is chained to.
This change makes the future move all its listeners to the future it is
chained to, and forward future listeners as well. It avoids long chains of
futures depending on each other.
Effectively, chained futures form equivalence classes. This makes the
equivalence classess all be represented by the future that every other element
depends on, and it applies path shortening to make the dependency graph as
flat as possible.
R=floitsch@google.com
Review URL: https://codereview.chromium.org//15942010
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@23807 260f80e4-7a28-3924-810f-c04153c831b5