get-promise-state
Wraps the global Promise object to add a state getters.
Usage
npm install get-promise-state
require("get-promise-state"); // Wraps the Promise for the global context
let p = new Promise((res, rej) => {setTimeout(() => res(), 100)});
console.log(p.isPending); // true
console.log(p.isSettled); // false
console.log(p.isResolved); // false
console.log(p.isRejected); // false
console.log(p.chainLength); // 1
console.log(p.executed); // 0
await p;
console.log(p.isPending); // false
console.log(p.isSettled); // true
console.log(p.isResolved); // true
console.log(p.isRejected); // false
console.log(p.chainLength); // 1
console.log(p.executed); // 1
Constraints
- For every Promise (or chained function), a new chained function is made for (but your chains aren't altered). What this mean is that your
.then
s might not be as fast as possible. - This doesn't work with
AsyncFunction
s (e.g.async () => {}
) (yet!)