UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

29 lines (28 loc) 777 B
"use strict"; // @ts-nocheck Object.defineProperty(exports, "__esModule", { value: true }); exports.defer = void 0; /** * Defers invoking the `func` until the current call stack has cleared. Any * additional arguments are provided to `func` when it's invoked. * * @since 5.7.0 * @category Function * @param func The function to defer. * @param args The arguments to invoke `func` with. * @returns Returns the timer id. * @example * * ```js * defer(text => console.log(text), 'deferred') * // => Logs 'deferred' after one millisecond. * ``` */ function defer(func, ...args) { if (typeof func !== "function") { throw new TypeError("Expected a function"); } return setTimeout(func, 1, ...args); } exports.defer = defer; exports.default = defer;