Module: LeanPool

Defined in:
lib/lean_pool.rb,
lib/lean_pool/pool.rb,
lib/lean_pool/errors.rb,
lib/lean_pool/version.rb,
lib/lean_pool/http_pool.rb

Overview

LeanPool is a lightweight, process-free resource pool implementation for Ruby.

This module provides efficient resource management without creating per-resource processes, making it perfect for managing sockets, HTTP connections, ports, and other resources that need efficient pooling with minimal overhead.

The library is built on top of concurrent-ruby for reliable thread safety and provides a clean, Ruby-idiomatic interface for resource pooling.

Examples:

Basic usage with a Redis connection pool

require 'lean_pool'

pool = LeanPool::Pool.new(size: 5) do
  Redis.new(host: "localhost", port: 6379)
end

pool.checkout do |redis|
  redis.get("my_key")
  redis.set("my_key", "value")
end

Using HTTP connection pool

require 'lean_pool'

http_pool = LeanPool::HTTPPool.new("api.example.com", 443, size: 10, use_ssl: true)
response = http_pool.get("/users")
puts response[:body]

Custom resource pool with state

require 'lean_pool'

pool = LeanPool::Pool.new(
  size: 10,
  timeout: 5.0,
  lazy: true,
  pool_state: { database: "production", timeout: 30 }
) do |state|
  DatabaseConnection.new(
    database: state[:database],
    timeout: state[:timeout]
  )
end

pool.checkout do |db|
  db.query("SELECT * FROM users")
end

See Also:

Since:

  • 0.1.0

Defined Under Namespace

Classes: Error, HTTPPool, Pool, ResourceError, ShutdownError, TimeoutError

Constant Summary collapse

VERSION =

The current version of LeanPool.

Follows semantic versioning (MAJOR.MINOR.PATCH):

  • MAJOR: Breaking changes
  • MINOR: New features, backwards compatible
  • PATCH: Bug fixes, backwards compatible

Returns:

  • (String)

    The version string (e.g., "0.1.0")

Since:

  • 0.1.0

"0.1.0"