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.
It is supposed to be implemented with the same behavior with nodejs/browser native Promise. Test cases covered.
new Promise(fn: function(resolve, reject))
promise.then(onFulfilled: null|function(value), onRejected: null|function(reason))
promise.catch(onRejected: function(reason))
promise.finally(onRejected: function(valueOrReason))
Promise.resolve(value: *)
Promise.reject(reason: *)
Promise.all(promises: Array.<Promise | Thenable>)
Promise.race(promises: Array.<Promise | Thenable>)
Promise.onUnhandledRejection = function (reason) {
// ... handle your unhandled rejection
};