Commit c5309f92 authored by JC Brand's avatar JC Brand

Add attributes to resolveable promise to detect its resolved state

parent 5376d267
......@@ -314,12 +314,30 @@ u.getResolveablePromise = function () {
/* Returns a promise object on which `resolve` or `reject` can be
* called.
*/
const wrapper = {};
const wrapper = {
isResolved: false,
isPending: true,
isRejected: false
};
const promise = new Promise((resolve, reject) => {
wrapper.resolve = resolve;
wrapper.reject = reject;
})
_.assign(promise, wrapper);
promise.then(
function (v) {
promise.isResolved = true;
promise.isPending = false;
promise.isRejected = false;
return v;
},
function (e) {
promise.isResolved = false;
promise.isPending = false;
promise.isRejected = true;
throw (e);
}
);
return promise;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment