1.0.0 • Published 1 year ago

get-promise-state v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

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

  1. 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 .thens might not be as fast as possible.
  2. This doesn't work with AsyncFunctions (e.g. async () => {}) (yet!)