Skip to content

Synchronization using await 1

Ulf Wiger edited this page Jun 8, 2016 · 2 revisions

Designing a robust startup sequence in a complex system is a very difficult task.

Erlang/OTP offers some assistance with application dependencies, but these are fairly coarse-grained, and offer no help if (heaven forbid) dependencies are somewhat circular in nature.

Gproc provides a simple synchronization mechanism in the form of gproc:await(Name). This function works like gproc:where(Name), but will work even if Name is not yet registered; in this case, it will block until someone does register it.

Gproc allows a process to have several unique names, so processes can use this facility to register a name announcing that "I am now ready to serve requests of type X". This way, gproc becomes a simple resource broker.

Distributed synchronization

Naturally, gproc:await/1 works on global as well as on local names.

For those who need distributed synchronization and do not want to rely on global names, there are two functions:

  • gproc:await(Node, Name, Timeout) which works the same way as await/2, but checks for Name on the node Node.
  • gproc:wide_await(Nodes, Name, Timeout) which will wait for Name on any of Nodes
Clone this wiki locally