(functionName: string, args: unknown[])
| 64 | |
| 65 | // biome-ignore lint/suspicious/noExplicitAny: FIXME |
| 66 | async execute(functionName: string, args: unknown[]): Promise<any> { |
| 67 | if (!this.isInitialized) { |
| 68 | throw new Error('Worker pool not initialized'); |
| 69 | } |
| 70 | |
| 71 | // Try to get available worker |
| 72 | const worker = this.getAvailableWorker(); |
| 73 | |
| 74 | if (worker) { |
| 75 | // Worker available, execute immediately and trigger queue processing when done |
| 76 | return worker.call(functionName, args).finally(() => this.processQueue()); |
| 77 | } else { |
| 78 | // All workers busy, queue the request |
| 79 | return new Promise<unknown>((resolve, reject) => { |
| 80 | this.queue.push({ functionName, args, resolve, reject }); |
| 81 | logger.debug(`Request queued (queue size: ${this.queue.length})`); |
| 82 | }); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | private getAvailableWorker(): PythonWorker | null { |
| 87 | for (const worker of this.workers) { |
no test coverage detected