()
| 23 | let processing = false |
| 24 | |
| 25 | async function processQueue(): Promise<void> { |
| 26 | if (processing) return |
| 27 | if (queue.length === 0) return |
| 28 | |
| 29 | processing = true |
| 30 | |
| 31 | while (queue.length > 0) { |
| 32 | const { args, resolve, reject, context } = queue.shift()! |
| 33 | |
| 34 | try { |
| 35 | const result = await fn.apply(context, args) |
| 36 | resolve(result) |
| 37 | } catch (error) { |
| 38 | reject(error) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | processing = false |
| 43 | |
| 44 | // Check if new items were added while we were processing |
| 45 | if (queue.length > 0) { |
| 46 | void processQueue() |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | return function (this: unknown, ...args: T): Promise<R> { |
| 51 | return new Promise((resolve, reject) => { |
no test coverage detected