promise-then

Promises/A+ implementation


Keywords
promise, then, promises-aplus, flow control, thenable, async, asynchronous, asynchronous-programming
License
MIT
Install
npm install promise-then@0.1.1

Documentation

Promise/then

npm bundle size npm unit tests

This library is a kind of implementation for Promises/A+ specification which is a kind of typical solution for asynchronous flow control.

The entire callbacks calling are based on observer pattern. Not two different queues subscribe to a particular state (eg. fulfilled OR rejected), but just only one callbacks queue as subject's observer to observe the state changes of promise instance.

              callbacks
  (not a particular type of callbacks)
                  +
                  |
               observe
                  |
                  v
the state  changes of Promise instance
       (not a particular state)
                  +
                  |
               notify
                  |
                  v
          callbacks in queue
                  +
                  |
                call
                  |
                  v
      onFulfilled or onRejected

Installation

# using yarn
yarn add promise-then

# using npm
npm i promise-then

Usage

import Promiser from 'promise-then'

const promiser = new Promiser((resolve, reject) => {
  // ... omit unrelated code
  resolve(result) // or reject(reason)
})

promiser.then(
  result => {
    /* get `result` from promiser internal */
  },
  reason => {
    /* handle any error in the promiser */
  }
)

Unit tests

All unit tests have been handled by the official test suite.

# using yarn
yarn test

# using npm
npm t

Debug mode

Debug mode only works with Visual Studio Code breakpoint tutorial.

You can use those commands to run debug mode directly if necessary.

# using yarn
yarn run debug

# using npm
npm run debug

Further

License

MIT © Bowen Liu