diff options
author | Alex Early <alexander.early@gmail.com> | 2016-02-23 16:19:38 -0800 |
---|---|---|
committer | Alex Early <alexander.early@gmail.com> | 2016-02-23 16:19:38 -0800 |
commit | 3d1781cbb9a215b30fc03c2135309fe3579e5689 (patch) | |
tree | e26f489e37ae3a227867b3d1dfe6c04afa361c23 /lib/whilst.js | |
parent | 01205e053b16c7843a3d4d3c9075b33de5adb2d0 (diff) | |
parent | 070ed49496d5cf0b3c31a8091608610961191238 (diff) | |
download | async-3d1781cbb9a215b30fc03c2135309fe3579e5689.tar.gz |
Merge pull request #996 from caolan/modularization
Modularization
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); +} |