diff options
Diffstat (limited to 'lib/whilst.js')
-rw-r--r-- | lib/whilst.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/whilst.js b/lib/whilst.js new file mode 100644 index 0000000..feaec00 --- /dev/null +++ b/lib/whilst.js @@ -0,0 +1,15 @@ +'use strict'; + +import noop from 'lodash/noop'; +import rest from 'lodash/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); +} |