class Pool(T)

Overview

Generic pool.

It will create N instances that can be checkin then checkout. Trying to checkout an instance from an empty pool will block until another coroutine checkin an instance back, up until a timeout is reached.

Direct Known Subclasses

Defined in:

pool.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(capacity : Int32 = 5, timeout : Time::Span = 5.seconds, &block : -> T) #

[View source]

Instance Method Detail

def capacity : Int32 #

Returns how many instances can be started at maximum capacity.


[View source]
def checkin(connection : T) : Nil #

Checkin an instance back into the pool.


[View source]
def checkout : T #

Checkout an instance from the pool. Blocks until an instance is available if all instances are busy. Eventually raises an IO::Timeout error.


[View source]
def pending : Int32 #

Returns how many instances are available for checkout.


[View source]
def size : Int32 #

Returns how many instances have been started.


[View source]
def start_all #

[View source]
def timeout : Time::Span #

Returns how much time to wait for an instance to be available before raising a Timeout exception.


[View source]