Module gruff

Copyright © 2017 Jörgen Brandt

Version: 0.1.0

Authors: Jörgen Brandt (joergen.brandt@onlinehome.de).

Data Types

name()

name() = atom() | {atom(), atom()} | {global, term()} | {via, atom(), term()} | pid()

result()

result() = {ok, pid()} | ignore | {error, term()}

server_name()

server_name() = {local, atom()} | {global, atom()} | {via, atom(), term()}

Function Index

checkin/1Checks in a previously checked out worker instance.
checkout/1Checks out a worker instance from the worker pool.
checkout/2Checks out a worker instance from the worker pool with an explicit time out interval.
get_pid/1Returns the Pid of a worker object.
start_link/2Starts an instance of a gruff worker pool.
start_link/3Starts an instance of a gruff worker pool registered as ServerName.
stop/1Stops the gruff instance under the given name.
transaction/2Checks out a worker, applies a given function to it, and checks it in again.
transaction/3Checks out a worker, applies a given function to it, and checks it in again applying an explicit timeout.

Function Details

checkin/1

checkin(X1::{'\'?MODULE\'', Name, R, WrkPid}) -> ok

Checks in a previously checked out worker instance. The Name argument identifies the gruff instance and the WrkPid argument is the process id of a worker instance, that has previously been allocated using checkout/n.

checkout/1

checkout(Name) -> Result

Checks out a worker instance from the worker pool. Times out after five seconds.

See also: checkout/2.

checkout/2

checkout(Name, Timeout) -> Result

Checks out a worker instance from the worker pool with an explicit time out interval. Name is the name of the gruff process instance created with start_link/n. The result is either {ok, Pid} or {error, Reason} where Pid is the process id of the successfully allocated worker instance. The function times out after Timeout milliseconds.

get_pid/1

get_pid(X1::{'\'?MODULE\'', name(), reference(), pid()}) -> pid()

Returns the Pid of a worker object.

start_link/2

start_link(X1::{M, F, A}, N) -> result()

Starts an instance of a gruff worker pool.

See also: start_link/4.

start_link/3

start_link(ServerName, X2::{M, F, A}, N) -> result()

Starts an instance of a gruff worker pool registered as ServerName. The workers are specified in the {M, F, A} triple denoting the worker module M, the start function F, and the start function's argument list A. N is the number of workers to be maintained by this worker pool. Returns {ok, Pid} on success. Returns ignore or {error, Reason} otherwise.

stop/1

stop(Name) -> ok

Stops the gruff instance under the given name.

transaction/2

transaction(Name, Fun) -> {ok, term()} | {error, term()}

Checks out a worker, applies a given function to it, and checks it in again. Times out after five seconds.

See also: transaction/3.

transaction/3

transaction(Name, Fun, Timeout) -> {ok, term()} | {error, term()}

Checks out a worker, applies a given function to it, and checks it in again applying an explicit timeout. The gruff instance identified by the Name argument is used to check out a worker and apply the unary function Fun to it. Afterwards, the worker instance is checked in again. On success, transaction/3 returns {ok, Value} where Value is the return value of the given function Fun. If the function throws an exception or the checkout fails or times out then {error, Reason} is returned.


Generated by EDoc