(fn: PoolTask<M, F, S, RESP, TYPE_MAPPING, T>)
| 444 | } |
| 445 | |
| 446 | execute<T>(fn: PoolTask<M, F, S, RESP, TYPE_MAPPING, T>) { |
| 447 | return new Promise<Awaited<T>>((resolve, reject) => { |
| 448 | if (this._self.#isClosing || !this._self.#isOpen) { |
| 449 | return reject(new ClientClosedError()); |
| 450 | } |
| 451 | |
| 452 | const waitStartTimestamp = performance.now(); |
| 453 | const client = this._self.#idleClients.shift(), |
| 454 | { tail } = this._self.#tasksQueue; |
| 455 | if (!client) { |
| 456 | let timeout; |
| 457 | if (this._self.#options.acquireTimeout > 0) { |
| 458 | timeout = setTimeout( |
| 459 | () => { |
| 460 | this._self.#tasksQueue.remove(task, tail); |
| 461 | reject(new TimeoutError('Timeout waiting for a client')); // TODO: message |
| 462 | }, |
| 463 | this._self.#options.acquireTimeout |
| 464 | ); |
| 465 | } |
| 466 | |
| 467 | const task = this._self.#tasksQueue.push({ |
| 468 | timeout, |
| 469 | // @ts-expect-error -- resolve generic variance |
| 470 | resolve, |
| 471 | reject, |
| 472 | fn, |
| 473 | waitStartTimestamp, |
| 474 | }); |
| 475 | |
| 476 | if (this.totalClients < this._self.#options.maximum) { |
| 477 | this._self.#create(); |
| 478 | } |
| 479 | |
| 480 | return; |
| 481 | } |
| 482 | |
| 483 | const node = this._self.#clientsInUse.push(client); |
| 484 | publish(CHANNELS.POOL_CONNECTION_WAIT, () => ({ clientId: client._clientId, waitStartTimestamp })); |
| 485 | // @ts-expect-error -- resolve generic variance |
| 486 | this._self.#executeTask(node, resolve, reject, fn); |
| 487 | }); |
| 488 | } |
| 489 | |
| 490 | #executeTask( |
| 491 | node: DoublyLinkedNode<RedisClientType<M, F, S, RESP, TYPE_MAPPING>>, |
no test coverage detected