Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed in ce72180 there was mention of a desire for a connection pool. The
crystal-lang/crystal-db
shard is capable of managing pools of arbitrary connection types, includingHTTP::Client
s — really, anything with aclose
method).This commit adds
DB::Pool
for a thread-safe, configurable connection pool. By default, it spins up a single connection on instantiation and will close all but one connection on checking connections back into the pool. This commit does not add configurability to that connection pool, but it can be added in a followup commit.DB::Pool
is used in several of my own shards that implement network clients:DB::Pool
, which was the catalyst for Allow DB::Pool to be used a generic connection pool crystal-lang/crystal-db#131 enabling this functionality)A couple other minor touches in this commit include:
nil
check on@callback
before_request
, favoring assignment from within the method signatureThese would've been separate PRs, but they would not have been able to be done concurrently due to merge conflicts so I shoveled them all in here. 😄