Promise-Handy-Extension
Promise-Handy-Extension is a pretty simple ES6 promise extension. You can use it in node/browser ENV which has implemented Promises/A+ specification.
Installation
$ npm install promise-handy-extension
Usage
How to import:
commonJS:
;
ES6:
// ES6:;
Use it directly in browse:
<script type="text/javascript" src="../release/promiseHandyExtension.min.js"></script>...</script>
Then the Promise object will be extended with these methods:
PromiseseriesPromisereduce...
How to use:
Promise.series
// an asyncCall: { // which will return a promise; return Promise;} Promise;
The key point here for this method is the execution order is guaranteed which means only when the returned promise asyncCall(input1) is resolved, we will execute asyncCall(input2) to get the next promise to execute. This is why it called 'series'.
If one promise is rejected, it will fail fast: Promise.series will reject immediately.
For more detailed example, please check the test case which shows how this handy method can control your promise execute flow:
Promise.reduce
// an asyncCall: { // which will return a promise; return Promise;} Promise;
The key point here for this method is the execution order is guaranteed which means only when the returned promise asyncCall(input1) is resolved, we will execute asyncCall(input2) to get the next promise to execute in reduce way.
If one promise is rejected, it will fail fast: Promise.reduce will reject immediately.
For more detailed example, please check the test case which shows how this handy method can control your promise execute flow: