summaryrefslogtreecommitdiff
path: root/build-es/whilst.js
blob: 2f5c2ef17e6cb10330a8bcca2910dd4e27d496d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
'use strict';

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

export default function whilst(test, iterator, cb) {
    cb = cb || noop;
    if (!test()) return cb(null);
    var next = rest(function(err, args) {
        if (err) return cb(err);
        if (test.apply(this, args)) return iterator(next);
        cb.apply(null, [null].concat(args));
    });
    iterator(next);
}