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

Side by Side Diff: lib/src/result_future.dart

Issue 1214843004: Added a `ResultFuture` class. (Closed) Base URL: git@github.com:dart-lang/async.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/async.dart ('k') | test/result_future_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library async.result_future;
6
7 import 'dart:async';
8
9 import '../result.dart';
10 import 'delegate/future.dart';
11
12 /// A [Future] wrapper that provides synchronous access to the result of the
13 /// wrapped [Future] once it's completed.
14 class ResultFuture<T> extends DelegatingFuture<T> {
Lasse Reichstein Nielsen 2015/07/08 11:01:56 I think I'd prefer if this was not a Future itself
nweiz 2015/07/09 01:18:38 This is designed for the use-case of a class that
Lasse Reichstein Nielsen 2015/07/09 11:18:20 I can see the argument - whether a future is compl
nweiz 2015/07/13 20:05:52 I'd be okay with changing this to just have an [is
15 /// The wrapped [Future].
16 Future<T> _future;
Lasse Reichstein Nielsen 2015/07/09 11:18:20 I don't think this field is used at all.
nweiz 2015/07/13 20:05:52 Done.
17
18 /// The result of the wrapped [Future], if it's completed.
19 ///
20 /// If it hasn't completed yet, this will be `null`.
21 Result<T> get result => _result;
22 Result<T> _result;
23
24 factory ResultFuture(Future<T> future) {
25 var resultFuture;
26 resultFuture = new ResultFuture._(future.then((value) {
27 resultFuture._result = new Result.value(value);
28 return value;
29 }).catchError((error, stackTrace) {
30 resultFuture._result = new Result.error(error, stackTrace);
31 throw error;
32 }));
Lasse Reichstein Nielsen 2015/07/08 11:01:57 The `Result.capture(Future future)` can handle thi
nweiz 2015/07/09 01:18:38 Done.
33 return resultFuture;
34 }
35
36 ResultFuture._(Future<T> future)
37 : super(future);
38 }
OLDNEW
« no previous file with comments | « lib/async.dart ('k') | test/result_future_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698