[erlang-questions] gproc Help

Andrew Berman rexxe98@REDACTED
Fri Jun 22 23:19:28 CEST 2012


I'm trying to use gproc as a very basic pub/sub.  Here is example code I
have (very basic):

-module(test).

-compile([export_all]).

new() ->
    Pid = spawn_link(?MODULE, apply, []),
    gproc_ps:subscribe(l, test),
    Pid.

apply() ->
    receive
        {gproc_ps_event, test, Msg} -> io:put_chars(Msg),
        apply()
    end.

publish() ->
    gproc_ps:publish(l, test, "My test message").

In the shell I then do:

Pid = test:new().
test:publish().

My expectation was that I would get an output of "My test message", but all
I get is {gproc_ps_event,test,"My test message"}.  When I do a flush(), I
do get the Shell got {gproc_ps_event,test,"My test message"}.  What am I
doing wrong?  I obviously don't understand something, can someone explain
how to get this simple example to work.  I know I can do Pid ! {....} in
this example, but I'm trying to play with gproc.

Thanks for any help!

Andrew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120622/2578b40f/attachment.htm>


More information about the erlang-questions mailing list