summaryrefslogtreecommitdiff
path: root/lib/doWhilst.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/doWhilst.js')
-rw-r--r--lib/doWhilst.js13
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/doWhilst.js b/lib/doWhilst.js
index d9222aa..4407305 100644
--- a/lib/doWhilst.js
+++ b/lib/doWhilst.js
@@ -2,6 +2,7 @@ import noop from 'lodash/noop';
import rest from './internal/rest';
import onlyOnce from './internal/onlyOnce';
+import wrapAsync from './internal/wrapAsync';
/**
* The post-check version of [`whilst`]{@link module:ControlFlow.whilst}. To reflect the difference in
@@ -15,11 +16,10 @@ import onlyOnce from './internal/onlyOnce';
* @method
* @see [async.whilst]{@link module:ControlFlow.whilst}
* @category Control Flow
- * @param {Function} iteratee - A function which is called each time `test`
- * passes. The function is passed a `callback(err)`, which must be called once
- * it has completed with an optional `err` argument. Invoked with (callback).
+ * @param {AsyncFunction} iteratee - A function which is called each time `test`
+ * passes. Invoked with (callback).
* @param {Function} test - synchronous truth test to perform after each
- * execution of `iteratee`. Invoked with the non-error callback results of
+ * execution of `iteratee`. Invoked with any non-error callback results of
* `iteratee`.
* @param {Function} [callback] - A callback which is called after the test
* function has failed and repeated execution of `iteratee` has stopped.
@@ -28,10 +28,11 @@ import onlyOnce from './internal/onlyOnce';
*/
export default function doWhilst(iteratee, test, callback) {
callback = onlyOnce(callback || noop);
+ var _iteratee = wrapAsync(iteratee);
var next = rest(function(err, args) {
if (err) return callback(err);
- if (test.apply(this, args)) return iteratee(next);
+ if (test.apply(this, args)) return _iteratee(next);
callback.apply(null, [null].concat(args));
});
- iteratee(next);
+ _iteratee(next);
}