get-promise-state

1.0.0 • Public • Published

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!)

Readme

Keywords

none

Package Sidebar

Install

npm i get-promise-state

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

4.47 kB

Total Files

3

Last publish

Collaborators

  • thebrenny