ExPool v0.1.1 ExPool.State

The internal state of the pool.

This module defines a ExPool.State struct and the main functions for working with pool internal state.

Fields

  • stash - stash of available workers
  • monitors - store for the monitored references
  • queue - queue to store the waiting requests

Summary

Functions

Stores the given item and its associated reference

Returns the number of available workers

Adds an item to the queue

Gets a worker from the pool if there is any available

Gets an item from its reference

Keeps on the queue only items for those the function is true

Creates a new pool state with the given configuration

Pops an item from the queue

Returns the number of waiting processes

Gets a reference from its item

Removes the given item and its associated reference

Returns a worker to the pool

Returns the total number of workers

Types

Functions

add_monitor(state, item, ref)

Specs

add_monitor(t, item, ref) :: t

Stores the given item and its associated reference.

available_workers(state)

Specs

available_workers(t) :: non_neg_integer

Returns the number of available workers.

create_worker(state)

Specs

create_worker(t) :: {worker, t}
destroy_worker(state, worker)

Specs

destroy_worker(t, worker) :: t
enqueue(state, item)

Specs

enqueue(t, item) :: t

Adds an item to the queue.

get_worker(state)

Specs

get_worker(t) :: {:ok, {worker, t}} | {:empty, t}

Gets a worker from the pool if there is any available.

item_from_ref(state, ref)

Specs

item_from_ref(t, ref) :: {:ok, item} | :not_found

Gets an item from its reference.

keep_on_queue(state, filter)

Specs

keep_on_queue(t, (item -> boolean)) :: t

Keeps on the queue only items for those the function is true.

new(opts)

Specs

new(opts :: [Keyword]) :: t

Creates a new pool state with the given configuration.

Configuration options

  • :worker_mod - (Required) The worker module. It has to fit in a supervision tree (like a GenServer).

  • :size - (Optional) The size of the pool (default 5).
pop_from_queue(state)

Specs

pop_from_queue(t) :: {:ok, {item, t}} | {:empty, t}

Pops an item from the queue.

queue_size(state)

Specs

queue_size(t) :: non_neg_integer

Returns the number of waiting processes.

ref_from_item(state, item)

Specs

ref_from_item(t, item) :: {:ok, ref} | :not_found

Gets a reference from its item.

remove_monitor(state, item)

Specs

remove_monitor(t, item) :: t

Removes the given item and its associated reference.

report_dead_worker(state)

Specs

report_dead_worker(t) :: t
return_worker(state, worker)

Specs

return_worker(t, worker) :: t

Returns a worker to the pool.

size(state)

Specs

size(t) :: non_neg_integer

Returns the total number of workers.

total_workers(state)

Specs

total_workers(t) :: non_neg_integer