UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

40 lines (39 loc) 1.13 kB
"use strict"; // @ts-nocheck var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.delay = void 0; const isFunction_1 = __importDefault(require("./isFunction")); /** * @ignore * @private * @internal */ const FUNC_ERROR_TEXT = "Expected a function"; /** * Invokes `func` after `wait` milliseconds. Any additional arguments are * provided to `func` when it's invoked. * * @since 5.7.0 * @category Function * @param func The function to delay. * @param wait The number of milliseconds to delay invocation. * @param args The arguments to invoke `func` with. * @returns Returns the timer id. * @example * * ```js * delay(text => console.log(text), 1000, 'later') * // => Logs 'later' after one second. * ``` */ function delay(func, wait = 0, ...args) { if (!(0, isFunction_1.default)(func)) { throw new TypeError(FUNC_ERROR_TEXT); } return setTimeout(() => { func(...args); }, wait); } exports.delay = delay; exports.default = delay;