1 | /**
|
2 | * Delays the calling of a callback for a given amount of time.
|
3 | *
|
4 | * @example
|
5 | * ``` javascript
|
6 | * import { delay } from 'async-agent';
|
7 | *
|
8 | * delay(() => {
|
9 | * console.log('2');
|
10 | * }, 1000);
|
11 | *
|
12 | * console.log('1');
|
13 | *
|
14 | * // => 1
|
15 | * // (after 1000ms) => 2
|
16 | * ```
|
17 | *
|
18 | * @function delay
|
19 | *
|
20 | * @arg {Function} callback
|
21 | * @arg {Number} [duration=0]
|
22 | *
|
23 | * @returns {Number} An id that can be used to clear the callback before it gets called.
|
24 | */
|
25 | export default (callback, duration) => setTimeout(callback, duration);
|