promise-stateful

0.1.0 • Public • Published

promise-stateful

Native Promise wrapper with state getters (isPending, isFulfilled, isRejected).

Installation

npm install promise-stateful

Usage

import PromiseStateful from 'promise-stateful';

Constructor

Create a new promise the same way as you would with the Promise constructor:

  let p = new PromiseStateful((res, rej) => {
    // ...
  });

  p.isPending; // true
  p.isFulfilled; // false
  p.isRejected; // false

Also works with Promise static methods:

  let p = PromiseStateful.resolve('foo');

  p.isPending; // false
  p.isFulfilled; // true

PromiseStateful.from

Create a PromiseStateful from an existing Promise with PromiseStateful.from:

let nativePromise = Promise.resolve(123);
nativePromise.isFulfilled; // undefined

let p = PromiseStateful.from(nativePromise);
p.isFulfilled; // true

License

This software is released under the terms of the MIT license. See LICENSE.

Readme

Keywords

Package Sidebar

Install

npm i promise-stateful

Weekly Downloads

8

Version

0.1.0

License

MIT

Unpacked Size

2.82 kB

Total Files

3

Last publish

Collaborators

  • gavinhungry