1 | export default function async(arr, start, thenMethod, catchMethod, afterEach) {
|
2 | return arr.reduce((last, next) => {
|
3 | if(last !== start && afterEach) {
|
4 | last = last.then(afterEach)
|
5 | }
|
6 |
|
7 | if (next[thenMethod]) {
|
8 | last = last.then(args => next[thenMethod](...[].concat(args)));
|
9 | }
|
10 |
|
11 | if (next[catchMethod]) {
|
12 | last = last.catch(next[catchMethod]);
|
13 | }
|
14 |
|
15 | return last;
|
16 | }, start);
|
17 | }
|