Skip to content

Commit b688dee

Browse files
committed
feat(async): added PromiseWrapper.wrap
1 parent 71e0f89 commit b688dee

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

‎modules/angular2/src/facade/async.dart‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class PromiseWrapper {
1919
return promise.then(success, onError: onError);
2020
}
2121

22+
static Future wrap(Function fn) {
23+
return new Future(fn);
24+
}
25+
2226
// Note: We can't rename this method to `catch`, as this is not a valid
2327
// method name in Dart.
2428
static Future catchError(Future promise, Function onError) {

‎modules/angular2/src/facade/async.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ export class PromiseWrapper {
2828
return promise.then(success, rejection);
2929
}
3030

31+
static wrap<T>(computation: () => T): Promise<T> {
32+
return new Promise((res, rej) => {
33+
try {
34+
res(computation());
35+
} catch (e) {
36+
rej(e);
37+
}
38+
});
39+
}
40+
3141
static completer() {
3242
var resolve;
3343
var reject;

0 commit comments

Comments
 (0)