swarm v0.1.0 Swarm

This is the public Elixir API for :swarm.

Summary

Functions

Join a process to a group

Leave a process group

Returns a list of pids which are members of the given group

Call all members of a group and return the results as a list

Publish a message to all members of a group

Registers the given name to the given pid, however names registered this way will not be shifted when the cluster topology changes, but this allows you to use :swarm as a distributed process registry, including registering names with {:via, :swarm, name}

Similar to register_name/2, except this version takes module/function/args parameters, and starts the process, registers the pid with the given name, and handles cluster topology changes by restarting the process on it’s new node using the given MFA

Callback implementation for c:Application.start/2

Unregisters the given name from the registry

Get the pid of a registered name

Functions

join(group, pid)

Specs

join(term, pid) :: :ok

Join a process to a group

leave(group, pid)

Specs

leave(term, pid) :: :ok

Leave a process group

members(group)

Specs

members(term) :: [pid]

Returns a list of pids which are members of the given group.

multicall(group, msg, timeout \\ 5000)

Specs

multicall(term, term, pos_integer) :: [any]

Call all members of a group and return the results as a list.

Takes an optional timeout value. Any responses not received within this period are ignored. Default is 5s.

publish(group, msg)

Specs

publish(term, term) :: :ok

Publish a message to all members of a group.

register_name(name, pid)

Specs

register_name(term, pid) :: :yes | :no

Registers the given name to the given pid, however names registered this way will not be shifted when the cluster topology changes, but this allows you to use :swarm as a distributed process registry, including registering names with {:via, :swarm, name}.

register_name(name, module, function, args)

Specs

register_name(term, atom, atom, [term]) ::
  {:ok, pid} |
  {:error, term}

Similar to register_name/2, except this version takes module/function/args parameters, and starts the process, registers the pid with the given name, and handles cluster topology changes by restarting the process on it’s new node using the given MFA.

This version also returns an ok tuple with the pid if it registers successfully, or an error tuple if registration fails. You cannot use this with processes which are already started, it must be started by :swarm.

start(type, args)

Callback implementation for c:Application.start/2.

unregister_name(name)

Specs

unregister_name(term) :: :ok

Unregisters the given name from the registry.

whereis_name(name)

Specs

whereis_name(term) :: pid | :undefined

Get the pid of a registered name.