1 | //
|
2 | ;
|
3 |
|
4 | const chainFuncsAsync = (result, func) => result.then(func);
|
5 | const chainFuncsSync = (result, func) => func(result);
|
6 |
|
7 | /**
|
8 | * Runs the given functions sequentially. If the `init` param is a promise,
|
9 | * functions are chained using `p.then()`. Otherwise, functions are chained by passing
|
10 | * the result of each function to the next.
|
11 | */
|
12 | module.exports = function funcRunner(
|
13 | init ,
|
14 | funcs
|
15 | ) {
|
16 | const isAsync = init instanceof Promise;
|
17 |
|
18 | return funcs.reduce(
|
19 | isAsync === true ? chainFuncsAsync : chainFuncsSync,
|
20 | init
|
21 | );
|
22 | };
|