summaryrefslogtreecommitdiff
path: root/lib/internal/applyEach.js
blob: f95d8acf221b66380df6726544cd64783aed1ed7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import initialParams from './initialParams';
import wrapAsync from './wrapAsync';

export default function applyEach(eachfn) {
    return function(fns, ...callArgs) {
        var go = initialParams(function(args, callback) {
            var that = this;
            return eachfn(fns, (fn, cb) => {
                wrapAsync(fn).apply(that, args.concat(cb));
            }, callback);
        });
        if (callArgs.length) {
            return go.apply(this, callArgs);
        }
        return go;
    };
}