View Source wpool_pool (worker_pool v6.1.0)

A pool of workers. If you want to put it in your supervisor tree, remember it's a supervisor.

Link to this section Summary

Functions

Adds a callback module. The module must implement the
wpool_process_callbacks
behaviour.
Picks the worker with the smaller queue of messages.
Casts a message to all the workers within the given pool.
Picks the first available worker and sends the call to it. The timeout provided includes the time it takes to get a worker and for it to process the call.
Casts a message to the first available worker. Since we can wait forever for a wpool:cast to be delivered but we don't want the caller to be blocked, this function just forwards the cast when it gets the worker
Use this function to get the Worker pool record in a custom worker.
Retrieves the list of worker registered names. This can be useful to manually inspect the workers or do custom work on them.
Picks a worker base on a hash result.
phash2(Term, Range)
returns hash = integer, 0 <= hash < Range so
1
must be added
Set next within the worker pool record. Useful when using a custom strategy function.
Picks the first available worker, if any
Picks the next worker in a round robin fashion
Picks a random worker
Removes a callback module.
Picks the first available worker and sends the request to it. The timeout provided considers only the time it takes to get a worker
Starts a supervisor with several wpool_processes as its children
Retrieves the pool stats for all pools
Retrieves a snapshot of the pool stats
Get values from the worker pool record. Useful when using a custom strategy function.

Link to this section Types

-opaque wpool()

Link to this section Functions

Link to this function

add_callback_module(Pool, Module)

View Source
-spec add_callback_module(wpool:name(), module()) -> ok | {error, term()}.
Adds a callback module. The module must implement the
wpool_process_callbacks
behaviour.
-spec best_worker(wpool:name()) -> atom().
Picks the worker with the smaller queue of messages.
-spec broadcast(wpool:name(), term()) -> ok.
Casts a message to all the workers within the given pool.
Link to this function

call_available_worker(Name, Call, Timeout)

View Source
-spec call_available_worker(wpool:name(), any(), timeout()) -> atom().
Picks the first available worker and sends the call to it. The timeout provided includes the time it takes to get a worker and for it to process the call.
Link to this function

cast_to_available_worker(Name, Cast)

View Source
-spec cast_to_available_worker(wpool:name(), term()) -> ok.
Casts a message to the first available worker. Since we can wait forever for a wpool:cast to be delivered but we don't want the caller to be blocked, this function just forwards the cast when it gets the worker
-spec find_wpool(atom()) -> undefined | wpool().
Use this function to get the Worker pool record in a custom worker.
-spec get_workers(wpool:name()) -> [atom()].
Retrieves the list of worker registered names. This can be useful to manually inspect the workers or do custom work on them.
Link to this function

hash_worker(Name, HashKey)

View Source
-spec hash_worker(wpool:name(), term()) -> atom().
Picks a worker base on a hash result.
phash2(Term, Range)
returns hash = integer, 0 <= hash < Range so
1
must be added
-spec next(pos_integer(), wpool()) -> wpool().
Set next within the worker pool record. Useful when using a custom strategy function.
Link to this function

next_available_worker(Name)

View Source
-spec next_available_worker(wpool:name()) -> atom().
Picks the first available worker, if any
-spec next_worker(wpool:name()) -> atom().
Picks the next worker in a round robin fashion
-spec random_worker(wpool:name()) -> atom().
Picks a random worker
Link to this function

remove_callback_module(Pool, Module)

View Source
-spec remove_callback_module(wpool:name(), module()) -> ok | {error, term()}.
Removes a callback module.
Link to this function

send_request_available_worker(Name, Call, Timeout)

View Source
-spec send_request_available_worker(wpool:name(), any(), timeout()) ->
                                 noproc | timeout | gen_server:request_id().
Picks the first available worker and sends the request to it. The timeout provided considers only the time it takes to get a worker
Link to this function

start_link(Name, Options)

View Source
-spec start_link(wpool:name(), [wpool:option()]) ->
              {ok, pid()} | {error, {already_started, pid()} | term()}.
Starts a supervisor with several wpool_processes as its children
-spec stats() -> [wpool:stats()].
Retrieves the pool stats for all pools
-spec stats(wpool:name()) -> wpool:stats().
Retrieves a snapshot of the pool stats
-spec worker_name(wpool:name(), pos_integer()) -> atom().
-spec wpool_get(atom(), wpool()) -> any();
         ([atom()], wpool()) -> any().
Get values from the worker pool record. Useful when using a custom strategy function.