MCPcopy Create free account
hub / github.com/coopernurse/node-pool / _dispatchPooledResourceToNextWaitingClient

Method _dispatchPooledResourceToNextWaitingClient

lib/Pool.js:273–290  ·  view source on GitHub ↗

* Dispatches a pooledResource to the next waiting client (if any) else * puts the PooledResource back on the available list * @param {PooledResource} pooledResource [description] * @return {Boolean} [description]

(pooledResource)

Source from the content-addressed store, hash-verified

271 * @return {Boolean} [description]
272 */
273 _dispatchPooledResourceToNextWaitingClient(pooledResource) {
274 const clientResourceRequest = this._waitingClientsQueue.dequeue();
275 if (
276 clientResourceRequest === undefined ||
277 clientResourceRequest.state !== Deferred.PENDING
278 ) {
279 // While we were away either all the waiting clients timed out
280 // or were somehow fulfilled. put our pooledResource back.
281 this._addPooledResourceToAvailableObjects(pooledResource);
282 // TODO: do need to trigger anything before we leave?
283 return false;
284 }
285 const loan = new ResourceLoan(pooledResource, this._Promise);
286 this._resourceLoans.set(pooledResource.obj, loan);
287 pooledResource.allocate();
288 clientResourceRequest.resolve(pooledResource.obj);
289 return true;
290 }
291
292 /**
293 * tracks on operation using given set

Callers 2

_testOnBorrowMethod · 0.95
_dispatchResourceMethod · 0.95

Calls 4

dequeueMethod · 0.80
allocateMethod · 0.80
resolveMethod · 0.45

Tested by

no test coverage detected