ExPool v0.1.1 ExPool.Pool

Pool GenServer.

It provides an interface to start a pool, check in and check out workers.

alias ExPool.Pool

# Starts a new pool
{:ok, pool} = Pool.start_link(config)

# Blocks until there is a worker available
worker = Pool.check_out(pool)

# do some work with the worker

# Returns the worker to the pool
:ok = Pool.check_in(pool, worker)

Summary

Functions

Returns a worker into the pool to be used by other processes

Retrieve a worker from the pool

Get information about the current state of the pool

Starts a new pool GenServer

Functions

check_in(pool, worker)

Specs

check_in(pool :: pid, worker :: pid) :: :ok

Returns a worker into the pool to be used by other processes.

check_out(pool)

Specs

check_out(pool :: pid) :: worker :: pid

Retrieve a worker from the pool.

If there aren’t any available workers it blocks until one is available.

info(pool)

Specs

info(pool :: pid) :: map

Get information about the current state of the pool.

start_link(opts \\ [])

Specs

start_link(opts :: [Keyword]) :: Supervisor.on_start

Starts a new pool GenServer.

Options:

  • :name - (Optional) The name of the pool

  • The rest of the options will be passed to the internal state as pool configuration (for more information about the available options check ExPool.Pool.State.new/1).