| Index: corelib/src/implementation/future_implementation.dart
|
| diff --git a/corelib/src/implementation/future_implementation.dart b/corelib/src/implementation/future_implementation.dart
|
| index 47c1e5d8c07ac628f806556c1f7e1b1e0de3fc1c..48c7d405b7c0d58f31143d1268c6ac93c1d66a79 100644
|
| --- a/corelib/src/implementation/future_implementation.dart
|
| +++ b/corelib/src/implementation/future_implementation.dart
|
| @@ -55,6 +55,10 @@ class FutureImpl<T> implements Future<T> {
|
| _exceptionHandled = false;
|
| }
|
|
|
| + FutureImpl.immediate(T value) : this() {
|
| + _setValue(value);
|
| + }
|
| +
|
| T get value() {
|
| if (!isComplete) {
|
| throw new FutureNotCompleteException();
|
| @@ -134,6 +138,48 @@ class FutureImpl<T> implements Future<T> {
|
| _exception = exception;
|
| _complete();
|
| }
|
| +
|
| + Future transform(Function transformation) {
|
| + final completer = new Completer();
|
| + handleException((e) {
|
| + completer.completeException(e);
|
| + return true;
|
| + });
|
| + then((v) {
|
| + var transformed = null;
|
| + try {
|
| + transformed = transformation(v);
|
| + } catch (final e) {
|
| + completer.completeException(e);
|
| + return;
|
| + }
|
| + completer.complete(transformed);
|
| + });
|
| + return completer.future;
|
| + }
|
| +
|
| + Future chain(Function transformation) {
|
| + final completer = new Completer();
|
| + handleException((e) {
|
| + completer.completeException(e);
|
| + return true;
|
| + });
|
| + then((v) {
|
| + var future = null;
|
| + try {
|
| + future = transformation(v);
|
| + } catch (final e) {
|
| + completer.completeException(e);
|
| + return;
|
| + }
|
| + future.handleException((e) {
|
| + completer.completeException(e);
|
| + return true;
|
| + });
|
| + future.then((b) => completer.complete(b));
|
| + });
|
| + return completer.future;
|
| + }
|
| }
|
|
|
| class CompleterImpl<T> implements Completer<T> {
|
|
|