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

Unified Diff: corelib/src/implementation/future_implementation.dart

Issue 9372008: patch from issue 9360020 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « corelib/src/future.dart ('k') | tests/corelib/corelib-leg.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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> {
« no previous file with comments | « corelib/src/future.dart ('k') | tests/corelib/corelib-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698