Tarearbol.Pool (tarearbol v1.6.2) View Source

The pool of workers built on top of Tarearbol.DynamicManager.

Configuration options:

  • pool_size the size of the pool, default: 5
  • payload the default payload for all the workers (for more complex initialization, use init option below)
  • init custom init step as described in Tarearbol.DynamicManager docs

This module exports defsynch/2 and defasynch/2 macros allowing to to declare functions that would be managed by a pool behind. Basically, the below would be translated into a message passed to the free worker of the pool.

defsynch synch(n) do
  {:ok, payload!() + n}
end

Both macros have three predefined functions declared inside a block

  • id! returning the id of the worker invoked
  • payload! returning the payload of the worker invoked
  • state! returning the state of the worker invoked as a tuple {id, payload}

Link to this section Summary

Functions

Declares an asynchronous function with the same name and block, that will be under the hood routed to the free worker to execute. If there is no free worker at the moment, returns :error otherwise returns {:ok, result} tuple.

Declares a synchronous function with the same name and block, that will be under the hood routed to the free worker to execute. If there is no free worker at the moment, returns :error otherwise returns {:ok, result} tuple.

Link to this section Functions

Link to this macro

defasynch(definition, opts \\ [])

View Source (macro) (since 1.4.0)

Declares an asynchronous function with the same name and block, that will be under the hood routed to the free worker to execute. If there is no free worker at the moment, returns :error otherwise returns {:ok, result} tuple.

This function might return any response recognizable by Tarearbol.DynamicManager.response/0.

Link to this macro

defsynch(definition, opts \\ [])

View Source (macro) (since 1.4.0)

Declares a synchronous function with the same name and block, that will be under the hood routed to the free worker to execute. If there is no free worker at the moment, returns :error otherwise returns {:ok, result} tuple.

This function might return any response recognizable by Tarearbol.DynamicManager.response/0.