UNPKG

515 BJavaScriptView Raw
1import delay from './delay.js';
2
3/**
4 * Defers the calling of a callback until the current stack is complete.
5 *
6 * @example
7 * ``` javascript
8 * import { defer } from 'async-agent';
9 *
10 * defer(() => {
11 * console.log('2');
12 * });
13 *
14 * console.log('1');
15 *
16 * // => 1
17 * // => 2
18 * ```
19 *
20 * @function defer
21 *
22 * @arg {Function} callback
23 *
24 * @returns {Number} An id that can be used to clear the callback before it gets called.
25 */
26export default (callback) => delay(callback, 0);