node-pool icon indicating copy to clipboard operation
node-pool copied to clipboard

destory the pool after all idle connections is closed

Open cool-firer opened this issue 9 years ago • 1 comments

I set evictionRunIntervalMillis=1, when all the idle connection is closed, new connection immediately is created, what if i need to destory the pool after all idle connections is closed, how should i code?

cool-firer avatar Apr 05 '17 10:04 cool-firer

My first response is going to be that you probably don't want evictionRunIntervalMillis to be 1, as it sort of defeats the purpose of pool as you generally won't get to re-use resources much unless there is already something in the waiting queue. (but maybe that is what you want).

I don't think there is way to trigger destroy the pool upon all idle connections is closed (lets imagine for a second that was actually some event) as the pool itself doesn't event any sort of event for that.

You can call the following code at any point to close the pool

const poolClosedPromise = myPool.drain().then(function() {
    return myPool.clear();
});

poolClosedPromise.then(function(){
  // when we get here the pool is now closed!
})

I guess my question is, why do you want to do this? There maybe be another way to solve your problem.

sandfox avatar Apr 05 '17 11:04 sandfox