[erlang-questions] gproc Help

Bob Ippolito bob@REDACTED
Fri Jun 22 23:35:25 CEST 2012


You call gproc_ps:subscribe(l, test) from the spawned process instead of
from the shell process.

For example:

new() ->
    spawn_link(fun () -> gproc_ps:subscribe(l, test), ?MODULE:apply() end).

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

> Yes, but how do I have my new process subscribe to it?
>
> Thanks,
>
> Andrew
>
> On Fri, Jun 22, 2012 at 2:26 PM, Bob Ippolito <bob@REDACTED> wrote:
>
>> 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/08b2b729/attachment.htm>


More information about the erlang-questions mailing list