Expool v0.2.0 Expool

This module provides a simple interface for concurrent process usage. The Expool.create_pool/2 function is used to create a base pool of processes, and is then used for task submission using Expool.submit/2.

Summary

Functions

Creates a new set of size processes, adding them to a Map so they can be referenced at a later time. Parses various options using Expool.Options.parse/1, and potentially binds the pool to a name via Agent

Retrieves a registered pool by name or PID. This is a shorthand for calling the Agent manually, but it will return an error if a valid pool is not found

Submits a task to a pool, either provided or by name. Returns error tuples if the pool is either inactive or invalid. If valid, a pid will be chosen based on the selection methods of the pool, and the task will be forwarded

Terminates all processes inside a pool, either provided or by name. Returns a pool marked as inactive to avoid developers sending uncaught messages through the pipeline

Functions

create_pool(size, opts \\ [])

Specs

create_pool(number, list) :: {atom, Expool}

Creates a new set of size processes, adding them to a Map so they can be referenced at a later time. Parses various options using Expool.Options.parse/1, and potentially binds the pool to a name via Agent.

Options

  • :name - a name to register the pool against (defaults to using nil)
  • :strategy - the balancing strategy to use (defaults to :round_robin)
get_pool(id)

Specs

get_pool(atom | pid) :: Expool

Retrieves a registered pool by name or PID. This is a shorthand for calling the Agent manually, but it will return an error if a valid pool is not found.

submit(pool, action)

Specs

submit(Expool | atom | pid, function) :: {atom, pid}

Submits a task to a pool, either provided or by name. Returns error tuples if the pool is either inactive or invalid. If valid, a pid will be chosen based on the selection methods of the pool, and the task will be forwarded.

If there is a name registered, the Agent will have the state updated when appropriate, to reflect any changes inside the pool.

terminate(pool)

Specs

terminate(Expool | atom | pid) :: Expool

Terminates all processes inside a pool, either provided or by name. Returns a pool marked as inactive to avoid developers sending uncaught messages through the pipeline.