summaryrefslogtreecommitdiff
path: root/build-es/during.js
blob: e9809cdc1edc96a2166f3ec01481558fb34cc67f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
'use strict';

import noop from 'lodash-es/noop';
import rest from 'lodash-es/rest';

export default function during(test, iterator, cb) {
    cb = cb || noop;

    var next = rest(function(err, args) {
        if (err) {
            cb(err);
        } else {
            args.push(check);
            test.apply(this, args);
        }
    });

    var check = function(err, truth) {
        if (err) return cb(err);
        if (!truth) return cb(null);
        iterator(next);
    };

    test(check);
}