coopernurse / node-pool

Generic resource pooling for node.js
2.37k stars 259 forks source link

Destroy resource after acquiring N times #255

Closed hyzyla closed 5 years ago

hyzyla commented 5 years ago

Is it possible to destroy resource after acquiring resource N times?

sandfox commented 5 years ago

There's nothing specifically in generic-pool that does this. However you might be able to implement something by adding a validate function to your factory object you supply to createPool. You might be able to add a "useCount" property to your resources, thats gets incremented when you use it, and then in your validate function you could check that. Otherwise you could add your own check before you return a resource to the pool. This check would look at the count and then release or destroy as appropriate.

hyzyla commented 5 years ago

Thanks, a lot!