summaryrefslogtreecommitdiff
path: root/lib/during.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/during.js')
-rw-r--r--lib/during.js25
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);
+}