diff options
author | Steve Robb <softnfuzzyrobb@gmail.com> | 2016-03-06 18:06:13 +0000 |
---|---|---|
committer | Steve Robb <softnfuzzyrobb@gmail.com> | 2016-03-06 18:06:13 +0000 |
commit | 20c0a9be73f517fcb7cda940675007416bb3aa0c (patch) | |
tree | 3cd0ca42c3375dd1c61c92ed0f6496631cc2ffad /lib/during.js | |
parent | 0858e09f203f9e358bdfa1ce84400e758bea68fc (diff) | |
parent | f38483cbccc16efe205b0bf1439c233e61a7f090 (diff) | |
download | async-20c0a9be73f517fcb7cda940675007416bb3aa0c.tar.gz |
Merge branch 'master' into autoInjectPR
Conflicts:
README.md
lib/async.js
test/test-async.js
Diffstat (limited to 'lib/during.js')
-rw-r--r-- | lib/during.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/during.js b/lib/during.js new file mode 100644 index 0000000..6b7c4d4 --- /dev/null +++ b/lib/during.js @@ -0,0 +1,25 @@ +'use strict'; + +import noop from 'lodash/noop'; +import rest from 'lodash/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); +} |