Chromium Code Reviews| Index: sdk/lib/async/future.dart |
| diff --git a/sdk/lib/async/future.dart b/sdk/lib/async/future.dart |
| index f2d926440737fa0f0e519f45eace8a395d21bd4c..14285b516baadffb97acab02942c131cc293aaa9 100644 |
| --- a/sdk/lib/async/future.dart |
| +++ b/sdk/lib/async/future.dart |
| @@ -85,6 +85,24 @@ part of dart.async; |
| // TODO(floitsch): document chaining. |
| abstract class Future<T> { |
| /** |
| + * Creates a future containing the result of calling [function]. |
| + * |
| + * The result of computing [:function():] is used to return |
| + * a completed future with that result. |
| + * If [function] returns a [Future], this will create a future that |
| + * will eventually complete with the same result. |
|
floitsch
2013/02/01 12:44:11
Maybe explain it in contrast to "immediate".
This
Lasse Reichstein Nielsen
2013/02/01 13:16:50
I think I'll do it the opposite way:
new Future.i
|
| + */ |
| + factory Future.of(function()) { |
| + try { |
| + var result = function(); |
| + if (result is Future) return new _FutureWrapper<T>(result); |
|
floitsch
2013/02/01 12:44:11
should we wrap?
Lasse Reichstein Nielsen
2013/02/01 13:16:50
That was my question too. I decided to do it just
|
| + return new _FutureImpl<T>.immediate(result); |
| + } catch (error, stackTrace) { |
| + return new _FutureImpl<T>.immediateError(error, stackTrace); |
| + } |
| + } |
| + |
| + /** |
| * A future whose value is available in the next event-loop iteration. |
| * |
| * See [Completer]s, for futures with values that are computed asynchronously. |