diff options
Diffstat (limited to 'lib/doWhilst.js')
-rw-r--r-- | lib/doWhilst.js | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/doWhilst.js b/lib/doWhilst.js index d9222aa..39f4600 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 @@ -19,7 +20,7 @@ import onlyOnce from './internal/onlyOnce'; * 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 {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 the 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 +29,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); } |