delay.js 795 B

1234567891011121314151617181920212223242526272829
  1. var baseDelay = require('./_baseDelay'),
  2. baseRest = require('./_baseRest'),
  3. toNumber = require('./toNumber');
  4. /**
  5. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  6. * provided to `func` when it's invoked.
  7. *
  8. * @static
  9. * @memberOf _
  10. * @since 0.1.0
  11. * @category Function
  12. * @param {Function} func The function to delay.
  13. * @param {number} wait The number of milliseconds to delay invocation.
  14. * @param {...*} [args] The arguments to invoke `func` with.
  15. * @returns {number} Returns the timer id.
  16. * @example
  17. *
  18. * _.delay(function(text) {
  19. * console.log(text);
  20. * }, 1000, 'later');
  21. * // => Logs 'later' after one second.
  22. */
  23. var delay = baseRest(function(func, wait, args) {
  24. return baseDelay(func, toNumber(wait) || 0, args);
  25. });
  26. module.exports = delay;