1.0.0 • Published 8 years ago

promise-aplus v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

Promise

Implementation of javascript Promise/A+ standard, plus .finally and onUnhandledRejection.

Nothing more. Clean and tiny (3.9 KB Only, or 1.4 KB gzipped).

Use it by: npm install beauty-promise, or include browser-bundles/promise.min.js.

  • Why not bluebird? -- Too large
  • Why not babel (core-js) runtime -- Too large (and simple)
  • Why not q -- Still too large
  • Why not then@promise -- Well, it's not quite large (although still larger than this one). But I don't feel good for its implementation of 'unhandled rejection tracking' - complex api, and the trigger is delayed.

What I want is a basic and tiny Promise, with useful 'unhandled rejection tracking' (which is only supported on Chrome for native Promise). So I created this one.

Promise API

It is supposed to be implemented with the same behavior with nodejs/browser native Promise. Test cases covered.

Constructor
new Promise(fn: function(resolve, reject))
Promise Instance Methods
promise.then(onFulfilled: null|function(value), onRejected: null|function(reason))
promise.catch(onRejected: function(reason))
promise.finally(onRejected: function(valueOrReason))
Static Methods
Promise.resolve(value: *)
Promise.reject(reason: *)
Promise.all(promises: Array.<Promise | Thenable>)
Promise.race(promises: Array.<Promise | Thenable>)
Unhandled Promise Rejection
Promise.onUnhandledRejection = function (reason) {
    // ... handle your unhandled rejection
};