(fn: (...args: any[]) => any, scope: any, ...args: any[])
| 7 | private queue: Task[] = []; |
| 8 | |
| 9 | public exec<T>(fn: (...args: any[]) => any, scope: any, ...args: any[]): Promise<T> { |
| 10 | return new Promise((resolve, reject) => { |
| 11 | const copyFn = async () => { |
| 12 | if (!fn) { |
| 13 | reject(new Error('Function is null!')); |
| 14 | return; |
| 15 | } |
| 16 | try { |
| 17 | const res = await fn.call(scope, ...args); |
| 18 | resolve(res); |
| 19 | } catch (e) { |
| 20 | reject(e); |
| 21 | } |
| 22 | }; |
| 23 | this.queue.push({ |
| 24 | fn: copyFn, |
| 25 | }); |
| 26 | if (this.executing) return; |
| 27 | this.execNextTask(); |
| 28 | }); |
| 29 | } |
| 30 | |
| 31 | private execNextTask() { |
| 32 | if (this.queue.length < 1) { |
no test coverage detected