MCPcopy
hub / github.com/redis/node-redis / execute

Method execute

packages/client/lib/client/pool.ts:446–488  ·  view source on GitHub ↗
(fn: PoolTask<M, F, S, RESP, TYPE_MAPPING, T>)

Source from the content-addressed store, hash-verified

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>>,

Callers 8

#createCommandMethod · 0.95
#createScriptCommandMethod · 0.95
sendCommandMethod · 0.95
MULTIMethod · 0.95
pool.spec.tsFile · 0.45
#createModuleCommandMethod · 0.45
transactionFunction · 0.45

Calls 6

publishFunction · 0.90
#createMethod · 0.80
#executeTaskMethod · 0.80
shiftMethod · 0.45
removeMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected