js promiseStatus
/**
* This function allow you to modify a JS Promise by adding some status properties.
* Based on: http://stackoverflow.com/questions/21485545/is-there-a-way-to-tell-if-an-es6-promise-is-fulfilled-rejected-resolved
* But modified according to the specs of promises : https://promisesaplus.com/
*/
function MakeQuerablePromise(promise) {
// Don't modify any promise that has been already modified.
if (promise.isResolved) return promise;
// Set initial state
var isPending = true;
var isRejected = false;
var isFulfilled = false;
// Observe the promise, saving the fulfillment in a closure scope.
var result = promise.then(
function(v) {
isFulfilled = true;
isPending = false;
return v;
},
function(e) {
isRejected = true;
isPending = false;
throw e;
}
);
result.isFulfilled = function() { return isFulfilled; };
result.isPending = function() { return isPending; };
result.isRejected = function() { return isRejected; };
return result;
}
Also in JavaScript:
- how to count specific letters in string js
- new keyword in js
- ionic 1 decorator example
- how to learn javascript
- react native flexbox 2 columns 1 fixed width
- javascript check if key exists in object
- jquery clear file input
- nodejs oauth2 request
- check member role discordjs 12
- postman test for true
- nodejs read file to array
- read data from url node js
- error: Error: Unable to resolve module `crypto` from `node_modules\crypto-js\core.js`: crypto could not be found within the project.
- java.lang.IllegalArgumentException: Can only download HTTP/HTTPS
- how to calculate average of array in javascript
- javascript remove last word from string
- how to set time out in js
- javascript string in multiple lines
- javascript join array
- react slick
- react merge two objects
- every possible pairing in an array javascript in new array
- args slice discord.js
- javascript set file input value to null