until.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 `fn` 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 `fn`'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 `fn`. Invoked with ().
  24. * @param {Function} fn - A function which is called each time `test` fails.
  25. * The function is passed a `callback(err)`, which must be called once it has
  26. * completed with an optional `err` argument. Invoked with (callback).
  27. * @param {Function} [callback] - A callback which is called after the test
  28. * function has passed and repeated execution of `fn` has stopped. `callback`
  29. * will be passed an error and any arguments passed to the final `fn`'s
  30. * callback. Invoked with (err, [results]);
  31. */
  32. function until(test, fn, callback) {
  33. (0, _whilst2.default)(function () {
  34. return !test.apply(this, arguments);
  35. }, fn, callback);
  36. }
  37. module.exports = exports['default'];