Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Issue 50373002: Change and documentat how completer handles futures. (Closed)

Created:
7 years, 1 month ago by Lasse Reichstein Nielsen
Modified:
7 years, 1 month ago
Reviewers:
floitsch
CC:
reviews_dartlang.org
Visibility:
Public.

Description

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 Committed: https://code.google.com/p/dart/source/detail?r=29518

Patch Set 1 #

Patch Set 2 : Change signature everywhere. #

Total comments: 9
Unified diffs Side-by-side diffs Delta from patch set Stats (+143 lines, -6 lines) Patch
M sdk/lib/async/future.dart View 1 chunk +10 lines, -2 lines 3 comments Download
M sdk/lib/async/future_impl.dart View 1 5 chunks +14 lines, -4 lines 6 comments Download
M tests/lib/async/future_test.dart View 3 chunks +119 lines, -0 lines 0 comments Download

Messages

Total messages: 6 (0 generated)
Lasse Reichstein Nielsen
7 years, 1 month ago (2013-10-29 07:23:09 UTC) #1
Lasse Reichstein Nielsen
7 years, 1 month ago (2013-10-29 07:23:11 UTC) #2
floitsch
I'm not convinced that we should reject Future errors, but otherwise LGTM. https://codereview.chromium.org/50373002/diff/30001/sdk/lib/async/future.dart File sdk/lib/async/future.dart ...
7 years, 1 month ago (2013-10-29 18:13:35 UTC) #3
Lasse Reichstein Nielsen
https://codereview.chromium.org/50373002/diff/30001/sdk/lib/async/future.dart File sdk/lib/async/future.dart (right): https://codereview.chromium.org/50373002/diff/30001/sdk/lib/async/future.dart#newcode508 sdk/lib/async/future.dart:508: * The argument [error] must not be `null`, and ...
7 years, 1 month ago (2013-10-30 09:22:16 UTC) #4
Lasse Reichstein Nielsen
Committed patchset #2 manually as r29518 (presubmit successful).
7 years, 1 month ago (2013-10-30 09:22:37 UTC) #5
floitsch
7 years, 1 month ago (2013-10-30 18:50:53 UTC) #6
Message was sent while issue was closed.
https://codereview.chromium.org/50373002/diff/30001/sdk/lib/async/future.dart
File sdk/lib/async/future.dart (right):

https://codereview.chromium.org/50373002/diff/30001/sdk/lib/async/future.dart...
sdk/lib/async/future.dart:508: * The argument [error] must not be `null`, and it
must not be a future.
On 2013/10/30 09:22:17, Lasse Reichstein Nielsen wrote:
> If the result of a future cannot be a future, I assumed that the error result
> couldn't either. In that case, we don't have a value to use here.
> Since you say that we won't wait for it, I assume you mean that the future
will
> be the error value. 
> I'm not sure I like the difference, *but* we do allow futures elsewhere if we
> throw them, e.g.,  
>   new Future(() { throw new Future.value(42); }).catchError((Future f) =>
> f).then(print);  // Prints 42
> 
> I'll change it back to allowing futures, and document it as such.
> Why not null, btw?
> 
Error handlers are frequently piped (like for example in streams: listen(...,
onDone: completer.complete(), onError: completer.completeError).
It would be annoying if they needed to look out for futures.
That said: it is clearly a really bad idea to make a future an error (especially
if the future completes with an error)

I'm not sure why we disallow null. I would be ok with allowing it as well.

Powered by Google App Engine
This is Rietveld 408576698