-
Notifications
You must be signed in to change notification settings - Fork 52
/
es6-wrapped-promise.js
37 lines (32 loc) · 986 Bytes
/
es6-wrapped-promise.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
module.exports = (Promise, ensureAslWrapper) => {
// Updates to this class should also be applied to the the ES3 version
// in index.js.
return class WrappedPromise extends Promise {
constructor(executor) {
var context, args;
super(wrappedExecutor);
var promise = this;
try {
executor.apply(context, args);
} catch (err) {
args[1](err);
}
return promise;
function wrappedExecutor(resolve, reject) {
context = this;
args = [wrappedResolve, wrappedReject];
// These wrappers create a function that can be passed a function and an argument to
// call as a continuation from the resolve or reject.
function wrappedResolve(val) {
ensureAslWrapper(promise, false);
return resolve(val);
}
function wrappedReject(val) {
ensureAslWrapper(promise, false);
return reject(val);
}
}
}
}
};