class ConnectionPool(T)

Overview

Sharing connections across coroutines.

Connections will be checkout from the pool and tied to the current fiber, until they are checkin, and thus be usable by another coroutine. Connections may also be manually checkout and checkin.

TODO reap connection of dead coroutines that didn't checkin (or died before)

Defined in:

connection.cr

Constructors

Instance Method Summary

Instance methods inherited from class Pool(T)

capacity : Int32 capacity, checkin(connection : T) : Nil checkin, checkout : T checkout, pending : Int32 pending, size : Int32 size, start_all start_all, timeout : Time::Span timeout

Constructor methods inherited from class Pool(T)

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

Constructor Detail

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

[View source]

Instance Method Detail

def active? #

Returns true if a connection was checkout for the current Fiber.


[View source]
def connection #

Returns the already checkout connection or checkout a connection then attaches it to the current Fiber.


[View source]
def connection(&) #

Yields a connection.

If a connection was already checkout for the curent Fiber, it will be yielded. Otherwise a connection will be checkout and tied to the current Fiber, passed to the block and eventually checkin.


[View source]
def release #

Releases the checkout connection for the current Fiber (if any).


[View source]