until.js

  1. import whilst from './whilst';
  2. /**
  3. * Repeatedly call `iteratee` until `test` returns `true`. Calls `callback` when
  4. * stopped, or an error occurs. `callback` will be passed an error and any
  5. * arguments passed to the final `iteratee`'s callback.
  6. *
  7. * The inverse of [whilst]{@link module:ControlFlow.whilst}.
  8. *
  9. * @name until
  10. * @static
  11. * @memberOf module:ControlFlow
  12. * @method
  13. * @see [async.whilst]{@link module:ControlFlow.whilst}
  14. * @category Control Flow
  15. * @param {Function} test - synchronous truth test to perform before each
  16. * execution of `iteratee`. Invoked with ().
  17. * @param {AsyncFunction} iteratee - An async function which is called each time
  18. * `test` fails. Invoked with (callback).
  19. * @param {Function} [callback] - A callback which is called after the test
  20. * function has passed and repeated execution of `iteratee` has stopped. `callback`
  21. * will be passed an error and any arguments passed to the final `iteratee`'s
  22. * callback. Invoked with (err, [results]);
  23. */
  24. export default function until(test, iteratee, callback) {
  25. whilst(function() {
  26. return !test.apply(this, arguments);
  27. }, iteratee, callback);
  28. }