until.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = until;
  6. var _whilst = require('./whilst');
  7. var _whilst2 = _interopRequireDefault(_whilst);
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. /**
  10. * Repeatedly call `iteratee` until `test` returns `true`. Calls `callback` when
  11. * stopped, or an error occurs. `callback` will be passed an error and any
  12. * arguments passed to the final `iteratee`'s callback.
  13. *
  14. * The inverse of [whilst]{@link module:ControlFlow.whilst}.
  15. *
  16. * @name until
  17. * @static
  18. * @memberOf module:ControlFlow
  19. * @method
  20. * @see [async.whilst]{@link module:ControlFlow.whilst}
  21. * @category Control Flow
  22. * @param {Function} test - synchronous truth test to perform before each
  23. * execution of `iteratee`. Invoked with ().
  24. * @param {AsyncFunction} iteratee - An async function which is called each time
  25. * `test` fails. Invoked with (callback).
  26. * @param {Function} [callback] - A callback which is called after the test
  27. * function has passed and repeated execution of `iteratee` has stopped. `callback`
  28. * will be passed an error and any arguments passed to the final `iteratee`'s
  29. * callback. Invoked with (err, [results]);
  30. */
  31. function until(test, iteratee, callback) {
  32. (0, _whilst2.default)(function () {
  33. return !test.apply(this, arguments);
  34. }, iteratee, callback);
  35. }
  36. module.exports = exports['default'];