Skip to content

Commit

Permalink
feat(async): added PromiseWrapper.wrap
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Jun 26, 2015
1 parent 71e0f89 commit b688dee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/angular2/src/facade/async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class PromiseWrapper {
return promise.then(success, onError: onError);
}

static Future wrap(Function fn) {
return new Future(fn);
}

// Note: We can't rename this method to `catch`, as this is not a valid
// method name in Dart.
static Future catchError(Future promise, Function onError) {
Expand Down
10 changes: 10 additions & 0 deletions modules/angular2/src/facade/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ export class PromiseWrapper {
return promise.then(success, rejection);
}

static wrap<T>(computation: () => T): Promise<T> {
return new Promise((res, rej) => {
try {
res(computation());
} catch (e) {
rej(e);
}
});
}

static completer() {
var resolve;
var reject;
Expand Down

0 comments on commit b688dee

Please sign in to comment.