
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Pond is a gem that offers thread-safe object pooling. It can wrap anything
that is costly to instantiate, but is usually used for connections. It is
intentionally very similar to the connection_pool
gem, but is intended to be
more efficient and flexible. It instantiates objects lazily by default, which
is important for things with high overhead like Postgres connections. It can
also be dynamically resized, and does not block on object instantiation.
Also, it was pretty fun to write.
Add this line to your application's Gemfile:
gem 'pond'
And then execute:
$ bundle
Or install it yourself as:
$ gem install pond
require 'pond'
require 'redis'
$redis_pond = Pond.new(:maximum_size => 5, :timeout => 0.5) { Redis.new }
# No connections are established until we need one:
$redis_pond.checkout do |redis|
redis.incr 'my_counter'
redis.lpush 'my_list', 'item'
end
# Alternatively, wrap it:
$redis = Pond.wrap(:maximum_size => 5, :timeout => 0.5) { Redis.new }
# You can now use $redis as you normally would.
$redis.incr 'my_counter'
$redis.lpush 'my_list', 'item'
$redis.pipelined do
# All these commands go to the same Redis connection, and so are pipelined correctly.
$redis.incr 'my_counter'
$redis.lpush 'my_list', 'item'
end
Options:
Pond::Timeout
error. The
default is 1. Integers or floats are both accepted.connection_pool
gem works.Sometimes objects in the pool outlive their usefulness (connections may fail) and it becomes necessary to remove them. Pond's detach_if option is useful for this - you can pass it any callable object, and Pond will pass it objects from the pool that have been checked out before they are checked back in. For example, when using Pond with PostgreSQL connections:
require 'pond'
require 'pg'
$pg_pond = Pond.new(:detach_if => lambda {|c| c.finished?}) do
PG.connect(:dbname => "pond_test")
end
Now, after a PostgreSQL connection has been used, but before it is returned to the pool, it will be passed to that lambda to see if it should be detached or not. If the lambda returns truthy, the connection will be detached (and made available for garbage collection), and a new one will be instantiated to replace it as necessary (until the pool returns to its maximum size).
I don't plan on adding too many more features to Pond, since I want to keep its design simple. If there's something you'd like to see it do, open an issue so we can discuss it before going to the trouble of creating a pull request.
FAQs
Unknown package
We found that pond demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.