diff options
Diffstat (limited to 'lib/whilst.js')
-rw-r--r-- | lib/whilst.js | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/whilst.js b/lib/whilst.js index 3311f4c..9012144 100644 --- a/lib/whilst.js +++ b/lib/whilst.js @@ -1,6 +1,8 @@ import noop from 'lodash/noop'; import rest from 'lodash/rest'; +import onlyOnce from './internal/onlyOnce'; + /** * Repeatedly call `fn`, while `test` returns `true`. Calls `callback` when * stopped, or an error occurs. @@ -37,11 +39,11 @@ import rest from 'lodash/rest'; * ); */ export default function whilst(test, iteratee, callback) { - callback = callback || noop; + callback = onlyOnce(callback || noop); if (!test()) return callback(null); var next = rest(function(err, args) { if (err) return callback(err); - if (test.apply(this, args)) return iteratee(next); + if (test()) return iteratee(next); callback.apply(null, [null].concat(args)); }); iteratee(next); |