1 | import wait from './wait.js';
|
2 | import waitBy from './waitBy.js';
|
3 |
|
4 | /**
|
5 | * Returns a function that returns a Promise that rejects with the results of a callback after a delay.
|
6 | *
|
7 | * @function rejectAfterBy
|
8 | * @category Higher-order
|
9 | *
|
10 | * @arg {Number} duration - Milliseconds
|
11 | * @arg {function} callback - Context and args are set to the same as those passed to the initially returned function.
|
12 | *
|
13 | * @returns {function(): Promise}
|
14 | */
|
15 | export default (duration, callback) => waitBy(function(resolve, reject, ...args) {
|
16 | wait(duration).then(() => reject(callback.apply(this, args)));
|
17 | });
|