-
-
Notifications
You must be signed in to change notification settings - Fork 232
Synchronization using await 1
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.
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 asawait/2
, but checks forName
on the nodeNode
. -
gproc:wide_await(Nodes, Name, Timeout)
which will wait forName
on any ofNodes