forked from uwiger/gproc
/
overview.edoc
51 lines (39 loc) · 1.93 KB
/
overview.edoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
@author Ulf Wiger <ulf.wiger@erlang-solutions.com>
@author Joseph Wayne Norton <norton@geminimobile.com>
@doc Extended process dictionary
== Introduction ==
Gproc is a process dictionary for Erlang, which provides a number of useful features beyond what the built-in dictionary has:
<ul>
<li>Use any term as a process alias</li>
<li>Register a process under several aliases</li>
<li>Non-unique properties can be registered simultaneously by many processes</li>
<li>QLC and match specification interface for efficient queries on the
dictionary</li>
<li>Await registration, let's you wait until a process registers itself</li>
<li>Atomically give away registered names and properties to another process</li>
<li>Counters, and aggregated counters, which automatically maintain the
total of all counters with a given name</li>
<li>Global registry, with all the above functions applied to a network of nodes</li>
</ul>
An interesting application of gproc is building publish/subscribe patterns.
Example:
<pre>
subscribe(EventType) ->
%% Gproc notation: {p, l, Name} means {(p)roperty, (l)ocal, Name}
gproc:reg({p, l, {?MODULE, EventType}}).
notify(EventType, Msg) ->
Key = {?MODULE, EventType},
gproc:send({p, l, Key}, {self(), Key, Msg}).
</pre>
Gproc has a QuickCheck test suite, covering a fairly large part of the local
gproc functionality, although none of the global registry. It requires a
commercial EQC license, but rebar is smart enough to detect whether EQC is
available, and if it isn't, the code in gproc_eqc.erl will be "defined away".
There is also an eunit suite, covering the basic operations for local and
global gproc.
== Building Edoc ==
By default, `./rebar doc` generates Github-flavored Markdown files.
If you want to change this, remove the `edoc_opts' line from `rebar.config'.
Gproc was first introduced at the ACM SIGPLAN Erlang Workshop in
Freiburg 2007 (<a href="erlang07-wiger.pdf">Paper available here</a>).
@end