srand (sbroker v1.1.1)
This modules provides utility functions for basic load balancing based on choosing a random process. It is designed for use with OTP behaviour messaging using via
names, e.g. {via, srand, {Process,...}}
. The third element, {Process,...}
, is a tuple containing pids (pid()
) and/or process names (atom()
, {global, any()}
, {via, module(), any()}
or {atom(), node()}
). An element is chosen randomly, if the element is a pid()
it is returned, otherwise the pid()
of the process name is looked up.
{atom(), node()}
if the node is not the local node. Therefore a registered name on another node is not supported for use with this module.
Link to this section Summary
Functions
Send a message to one element, selected randomly, in a tuple of process names. Returns
ok
if the element chosen is a pid()
. a locally registered name on another node, or a process is associated with the name. Otherwise exits.Lookup the pid or process name of one element, selected randomly, in a tuple of process names. If no process is associated with the name returns
undefined
.Link to this section Functions
Link to this function
send(Processes, Msg)
Specs
send(Processes, Msg) -> ok when Processes :: tuple(), Msg :: any().
ok
if the element chosen is a pid()
. a locally registered name on another node, or a process is associated with the name. Otherwise exits.
Link to this function
whereis_name(Processes)
Specs
whereis_name(Processes) -> Process | undefined when Processes :: tuple(), Process :: pid().
undefined
.