A minimal and clean implement of JavaScript ES6 Promise, which passes all standard test cases.
- multiple ES6 features are applied: const/let, Class, Symbol, => etc
- clean, explict and fast
- both available on back-end and front-end
> npm install clean-promise --save
You can use it like this in your own code:
const Promise = require('clean-promise');
Promise.all([Promise.resolve(1), 2, 3]).return(4444)
.tap(v => {
console.log('1 ' + v);
}).tap(v => {
console.log('2 ' + v);
}).return(3).tap(v => {
console.log('2 ' + v);
});
.then([function(any value) onResolved], [function(any error) onRejected]) -> Promise
.catch(function(any error) onRejected) -> Promise
.spread(function(any values...) cb, [onRejected]) -> Promise
.all(Iterable<any> | Promise<Iterable<any>> input) -> Promise
.map(function(any item, int index, int length) mapper, [function(any error) onRejected]) -> Promise
.return(Promise<any> | any value) -> Promise
.tap([function(any value) onResolved]) -> Promise
Promise.resolve(Promise<any> | any value) -> Promise
Promise.reject(any error) -> Promise
Promise.all(Iterable<any> | Promise<Iterable<any>> input) -> Promise
Promise.map(Iterable<any> | Promise<Iterable<any>> input, function(any item, int index, int length) mapper) -> Promise
Promise.race(Iterable<any> | Promise<Iterable<any>> input) -> Promise
Promise.try(function() fn) -> Promise
> npm test
- simplify and optimize code
- update README
- fix async bugs in .all & .return
- add .tap API
- finish all basical functions
- do some basical tests
- fix async bugs in Promise.all & Promise.map
- add .map API
MIT