Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-blocking versions of 'withResource', 'takeResource' #11

Merged
merged 1 commit into from
Feb 12, 2013

Conversation

kim
Copy link
Contributor

@kim kim commented Jan 27, 2013

This PR implements tryTakeResource and tryWithResource, which each return immediately if allocating a resource from the pool would block (because the pool is exhausted).

This is useful for implementing network clients which need to deal with many pools of connections to (potentially) many servers, such as distributed databases. In these cases, it is often desirable to employ some sort of retry strategy, or to balance operations across hosts. Thereby, it is also desirable to leave these decisions to the user, as opposed to implementing some magic behavior in the pool itself.

An alternative solution could be to provide introspection into the current pool usage. This, however, has the disadvantage of not being an atomic operation. Ie. a takeResource may still block, even though we've checked before that we didn't exceed maxResources.

Implementation note: there seemingly is some code duplication, but I figured I'd end up with quite some unnecessary boxing/unboxing otherwise.

bos added a commit that referenced this pull request Feb 12, 2013
Non-blocking versions of 'withResource', 'takeResource'
@bos bos merged commit b0197df into bos:master Feb 12, 2013
@bos
Copy link
Owner

bos commented Feb 12, 2013

Nice work, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants