Commit Graph

56 Commits

Author SHA1 Message Date
Lasse R.H. Nielsen 478602ad79 Fix errors in Future implementation around Future<Future<X>>.
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>
2020-12-14 16:34:28 +00:00
Lasse R.H. Nielsen 02923c6f83 Make Future.wait not return a const <Never>[] when given no futures.
Fixes #43445.

Bug: https://github.com/dart-lang/sdk/issues/43445
Change-Id: I70f722f6bee1d4cfe4d53a5f37bc29f0751edd78
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164162
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
2020-09-25 10:37:00 +00:00
Johnni Winther 645f3acca7 [cfe] Update greatest closure of ? to Object?
Closes #41386

Change-Id: I1a5a4cdc35cef37c7a8ba6a6aecb99457789bcdc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144940
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2020-05-04 08:14:43 +00:00
Liam Appelbe b65704e817 [nnbd] Fix lib/async/future_test in strong mode
Change-Id: Idaa06e9824c81009a0c719b9c1f8f698af104309
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143306
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2020-04-13 23:43:58 +00:00
Lasse R.H. Nielsen 8760283247 New implementation of runZoned.
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>
2020-03-25 00:24:33 +00:00
Robert Nystrom a2b556b937 Migrate lib_2/async to NNBD.
Change-Id: Ia5c41dda6503e1fbb8cc6099835d07588425e2ba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128310
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
2020-01-09 22:04:37 +00:00
Ben Konyi 42d354c91d Migrated test block 168 to Dart 2.0.
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 .
2017-08-21 00:59:34 -07:00
Lasse R.H. Nielsen 91e4917735 Fix test that assumed an async function returned a Future<not-dynamic>.
Review-Url: https://codereview.chromium.org/2788103002 .
2017-03-31 13:04:42 +02:00
Lasse R.H. Nielsen d509ddb3fa Use FutureOr more and make Future.sync return the resulting Future directly.
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/29202
R=floitsch@google.com

Review-Url: https://codereview.chromium.org/2790663003 .
2017-03-31 12:41:07 +02:00
Jacob Richman 14531fa62d Re-land "Format all multitests"
Only delta from the original is a bad merge of tests/corelib/list_test.dart

This reverts commit 44d8be0ed3.

BUG=

Review-Url: https://codereview.chromium.org/2774783002 .
2017-03-23 12:40:21 -07:00
Jacob Richman 44d8be0ed3 Revert "Format all multitests"
This reverts commit 312b66dd5f.

BUG=

Review-Url: https://codereview.chromium.org/2770063002 .
2017-03-23 10:49:40 -07:00
Jacob Richman 312b66dd5f Format all multitests
BUG=
R=rnystrom@google.com

Review-Url: https://codereview.chromium.org/2768073002 .
2017-03-23 10:26:44 -07:00
Jacob Richman 88eb557b65 Fix warnings_checker.dart handling of multitests
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 .
2017-03-21 17:29:56 -07:00
Jacob Richman bf2b545150 Revert "Update all tests"
This reverts commit ce76e9c30beaf9a193d3677b88c20a1ebb3fae8c.
2017-03-21 16:33:18 -07:00
Jacob Richman 3c7353d987 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

Review-Url: https://codereview.chromium.org/2765693002 .
2017-03-21 12:39:28 -07:00
Jacob Richman 6a7d6c385e Add comments
Add spaces to make sure dartfmt doesn't destroy bespoke indentation

BUG=
R=sra@google.com

Review-Url: https://codereview.chromium.org/2763823002 .
2017-03-20 21:03:12 -07:00
Florian Loitsch 70c48b9a2e Don't propagate synchronous Future.wait errors immediately.
Fixes #27249.

R=lrn@google.com

Review URL: https://codereview.chromium.org/2311923002 .
2016-09-06 11:57:43 +02:00
Florian Loitsch 33b7b45252 Deal with synchronous errors in Future.wait.
Synchronous errors are caught and piped into the returned future. This makes handling errors in Future.wait uniform.

Fixes #23656
BUG= http://dartbug.com/23656
R=lrn@google.com

Review URL: https://codereview.chromium.org/2252823004 .
2016-08-18 14:09:20 +02:00
Lasse R.H. Nielsen 06676c4719 Implement everything in test Future-class to avoid analyzer warnings.
Review URL: https://codereview.chromium.org/1968033002 .
2016-05-11 13:43:51 +02:00
Lasse R.H. Nielsen 63b71b4c24 Make _Future._chainForeignFuture not cause an assert.
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 .
2016-05-11 13:10:46 +02:00
Lasse R.H. Nielsen 8487d57e48 Add Future.any and Stream.fromFutures.
R=floitsch@google.com

Review URL: https://codereview.chromium.org/1563223002 .
2016-01-08 10:17:34 +01:00
Lasse R.H. Nielsen fbedc2b86f Also iprove Future.value(null) and documentation of some Stream related classes.
R=sgjesse@google.com

Review URL: https://codereview.chromium.org//1177343004.
2015-06-16 11:38:07 +02:00
lrn@google.com 312a21cc1a Make Completer.complete handle a Future with a misbehaving "then" call.
Instead of throwing and getting into an invalid state (isChained but won't ever
complete), the synchronous error from trying to call "then" is used to complete
the future.

This should never happen in practice - it requires a "then" implementation that
is missing or throwing even when given valid arguments.

R=sgjesse@google.com

Review URL: https://codereview.chromium.org//1025133004

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@44629 260f80e4-7a28-3924-810f-c04153c831b5
2015-03-23 09:09:32 +00:00
lrn@google.com 3a66c29a6d Add cleanUp function to Future.wait.
The cleanUp function is called on the values of successful futures,
so it can release any resources that were successfully allocated.

R=sgjesse@google.com

Review URL: https://codereview.chromium.org//815773002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@42730 260f80e4-7a28-3924-810f-c04153c831b5
2015-01-09 10:52:15 +00:00
lrn@google.com 181efd76ee Add missing null-tests to async error functions.
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
2014-09-25 11:00:49 +00:00
lrn@google.com 2ab1f1238f Trying to make preamble for d8.
Preamble handles timers and task queue.

R=floitsch@google.com

Review URL: https://codereview.chromium.org//201873002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@34967 260f80e4-7a28-3924-810f-c04153c831b5
2014-04-11 10:29:06 +00:00
lrn@google.com 8744794212 Change other futures to also have timeout take a named parameter.
Review URL: https://codereview.chromium.org//98683002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@30792 260f80e4-7a28-3924-810f-c04153c831b5
2013-12-02 09:13:49 +00:00
lrn@google.com e0314a6117 Add Future.timeout.
R=floitsch@google.com, nweiz@google.com

Review URL: https://codereview.chromium.org//91213002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@30745 260f80e4-7a28-3924-810f-c04153c831b5
2013-11-28 08:16:01 +00:00
floitsch@google.com 35e9ae50d9 Fix warnings in library-tests.
R=lrn@google.com

Review URL: https://codereview.chromium.org//54723007

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@29756 260f80e4-7a28-3924-810f-c04153c831b5
2013-11-01 17:01:11 +00:00
lrn@google.com 72e6685c6a Change and documentat how completer handles futures.
Completer.complete changes signature to accept 'var' and chain if the
argument is a future.
Completer.completeError throws if error is a future or null.
Documentation updated to match.
Fix error in implementation of completeError which dropped listeners when
chained. If the chained-to future is not a _Future, the listeners cannot
be forwarded.

BUG= http://dartbug.com/14211 http://dartbug.com/14212 http://dartbug.com/14435
R=floitsch@google.com

Review URL: https://codereview.chromium.org//50373002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@29518 260f80e4-7a28-3924-810f-c04153c831b5
2013-10-30 09:22:29 +00:00
kevmoo@j832.com 1a9178abe0 Handle Future result from Future.sync computation
BUG= https://code.google.com/p/dart/issues/detail?id=13368
R=floitsch@google.com

Review URL: https://codereview.chromium.org//23793006

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@27619 260f80e4-7a28-3924-810f-c04153c831b5
2013-09-18 13:42:52 +00:00
floitsch@google.com 68a9727c52 Rewrite Futures.
R=lrn@google.com

Committed: https://code.google.com/p/dart/source/detail?r=27375
Reverted: https://code.google.com/p/dart/source/detail?r=27376

Review URL: https://codereview.chromium.org//23926011

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@27383 260f80e4-7a28-3924-810f-c04153c831b5
2013-09-11 14:00:20 +00:00
floitsch@google.com d035cbd825 Revert "Rewrite Futures."
This reverts commit r27375.

Review URL: https://codereview.chromium.org//23967011

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@27376 260f80e4-7a28-3924-810f-c04153c831b5
2013-09-11 12:16:41 +00:00
floitsch@google.com 42e3d1db85 Rewrite Futures.
R=lrn@google.com

Review URL: https://codereview.chromium.org//23926011

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@27375 260f80e4-7a28-3924-810f-c04153c831b5
2013-09-11 12:02:37 +00:00
floitsch@google.com 113c812877 Replace ReceivePorts with asyncStart|End in some tests.
R=kustermann@google.com

Review URL: https://codereview.chromium.org//23522012

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@26996 260f80e4-7a28-3924-810f-c04153c831b5
2013-09-02 08:23:21 +00:00
lrn@google.com df6b4b13f8 Make _FutureImpl._chain do path shortening on listeners.
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
2013-06-10 12:27:46 +00:00
floitsch@google.com 968ebcff5a Make Completers asynchronous.
BUG= http://dartbug.com/9990
R=ajohnsen@google.com, lrn@google.com

Review URL: https://codereview.chromium.org//14690009

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@22417 260f80e4-7a28-3924-810f-c04153c831b5
2013-05-06 15:15:15 +00:00
floitsch@google.com 466d6670c1 Refactor Future constructors.
BUG=

Review URL: https://codereview.chromium.org//14070010

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@21517 260f80e4-7a28-3924-810f-c04153c831b5
2013-04-15 21:24:27 +00:00
floitsch@google.com 5431a5af54 Remove AsyncError with Expando.
Review URL: https://codereview.chromium.org//14251006

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@21498 260f80e4-7a28-3924-810f-c04153c831b5
2013-04-15 18:58:32 +00:00
floitsch@google.com 8fd6d0aafd Remove Expect from core library.
Committed: https://code.google.com/p/dart/source/detail?r=19755
Reverted: http://code.google.com/p/dart/source/detail?r=19756

Review URL: https://codereview.chromium.org//12212016

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@20996 260f80e4-7a28-3924-810f-c04153c831b5
2013-04-05 19:43:16 +00:00
floitsch@google.com 5dc8107c53 Revert "Remove Expect from core library."
This reverts commit 19755.

Review URL: https://codereview.chromium.org//12743005

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@19756 260f80e4-7a28-3924-810f-c04153c831b5
2013-03-09 03:19:07 +00:00
floitsch@google.com 12dbd2fd70 Remove Expect from core library.
Review URL: https://codereview.chromium.org//12212016

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@19755 260f80e4-7a28-3924-810f-c04153c831b5
2013-03-09 02:40:37 +00:00
lrn@google.com 96412ca371 Fix mising rename in tests of Future.isCompleted.
Review URL: https://codereview.chromium.org//12387012

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@19212 260f80e4-7a28-3924-810f-c04153c831b5
2013-02-28 11:54:19 +00:00
lrn@google.com cd4ae7e4af Add test for whether a completer or stream controller has been closed.
BUG=http://dartbug.com/8638

Review URL: https://codereview.chromium.org//12324004

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@19211 260f80e4-7a28-3924-810f-c04153c831b5
2013-02-28 11:36:54 +00:00
floitsch@google.com 02a5b031fe Change Future.delayed to take a Duration.
Review URL: https://codereview.chromium.org//12224081

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@18471 260f80e4-7a28-3924-810f-c04153c831b5
2013-02-13 19:31:22 +00:00
floitsch@google.com 3f7146707d Rework Timer interface.
Review URL: https://codereview.chromium.org//12213092

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@18326 260f80e4-7a28-3924-810f-c04153c831b5
2013-02-11 19:22:16 +00:00
lrn@google.com 11c5bd3d11 Add Future.of that calls a function and captures the result
This makes
  new Future.of(func)
equivalent to
  new Future.immediate(null).then((_) => func())
which should kill that idiom.

Review URL: https://codereview.chromium.org//12091105

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@17979 260f80e4-7a28-3924-810f-c04153c831b5
2013-02-01 13:15:42 +00:00
lrn@google.com 2ee344cd28 Add regression-test for badly chained future-impementations.
Review URL: https://codereview.chromium.org//12043013

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@17351 260f80e4-7a28-3924-810f-c04153c831b5
2013-01-21 13:10:10 +00:00
ngeoffray@google.com 184a9f610a Support Timer with 0 millisecond delay in dart2js running in the command line.
Review URL: https://codereview.chromium.org//11866003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@16968 260f80e4-7a28-3924-810f-c04153c831b5
2013-01-11 13:02:58 +00:00
lrn@google.com 4868ee2110 Remove Futures class, move methods to Future.
Optimize Future.forEach, Future.delay.

Review URL: https://codereview.chromium.org//11865005

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@16954 260f80e4-7a28-3924-810f-c04153c831b5
2013-01-11 09:46:45 +00:00