1 | import wait from './wait.js';
|
2 |
|
3 | /**
|
4 | * Returns a function that returns a Promise that calls a callback.
|
5 | *
|
6 | * @function waitBy
|
7 | * @category Higher-order
|
8 | *
|
9 | * @arg {function} callback - Context and args are set to the same as those passed to the initially returned function.
|
10 | *
|
11 | * @returns {function(...[*]): Promise<unknown>}
|
12 | */
|
13 | export default function(callback) {
|
14 | return function(...args) {
|
15 | const self = this;
|
16 |
|
17 | return wait((resolve, reject) => {
|
18 | callback.call(self, resolve, reject, ...args);
|
19 | });
|
20 | };
|
21 | }
|
22 |
|