Factory can be asked to validate pooled objects #54

merged 1 commit into from Jan 17, 2013

2 participants


Disclaimer: This is feature I needed but not sure if it's something that belongs to common codebase, so pull request just in case.

Some type of pooled objects, like TCP connections, can be unexpectedly invalidated by external reasons while they are in the pool. For example, socket can timeout or be closed by peer. Also peer restart can cause all socket objects in pool to become instantly "invalid".

Naturally its pool users responsibility to check if acquired object is still valid and remove it, but for simplicity it's good to have separate validation factory function to do sanity checks.

Trivial example:

validate: function(socket)  { return socket.writable; },

Validate is called only on acquire for pooled objects, not for freshly created. If validate returns false, pool destroys object.


Sorry I never reviewed this. This is a good idea. I'll merge it and get it in the next npm release.

@coopernurse coopernurse merged commit a6db3af into coopernurse:master Jan 17, 2013

1 check passed

Details default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment