[erlang-questions] gproc Help

Bob Ippolito bob@REDACTED
Fri Jun 22 23:26:57 CEST 2012


On Fri, Jun 22, 2012 at 5:19 PM, Andrew Berman <rexxe98@REDACTED> wrote:

> 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!
>

You're subscribing to 'test' from the shell process, not from Pid, so that
is why the shell is receiving the message.

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


More information about the erlang-questions mailing list