UNPKG

481 BJavaScriptView Raw
1import wait from './wait.js';
2import waitBy from './waitBy.js';
3
4/**
5 * Returns a function that returns a Promise that resolves with provided args after a delay.
6 *
7 * @function resolveAfterWith
8 * @category Higher-order
9 *
10 * @arg {Number} [duration=0] - Milliseconds
11 * @arg {*} [args] - Passed in to the resolve function.
12 *
13 * @returns {function(): Promise}
14 */
15export default (duration, ...args) => waitBy(function(resolve) {
16 wait(duration).then(() => resolve(...args));
17});