<div class="gmail_quote">On Fri, Jun 22, 2012 at 5:19 PM, Andrew Berman <span dir="ltr"><<a href="mailto:rexxe98@gmail.com" target="_blank">rexxe98@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'm trying to use gproc as a very basic pub/sub. Here is example code I have (very basic):<div><br></div><div><div>-module(test).</div><div><br></div><div>-compile([export_all]).</div><div><br></div><div>new() -> </div>
<div> Pid = spawn_link(?MODULE, apply, []),</div><div> gproc_ps:subscribe(l, test),</div><div> Pid.</div><div><br></div><div>apply() -></div><div> receive</div><div> {gproc_ps_event, test, Msg} -> io:put_chars(Msg),</div>
<div> apply()</div><div> end.</div><div><br></div><div>publish() -></div><div> gproc_ps:publish(l, test, "My test message").</div></div><div><br></div><div>In the shell I then do:</div><div><br>
</div>
<div>Pid = test:new().</div><div>test:publish().</div><div><br></div><div>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.</div>
<div><br></div><div>Thanks for any help!</div></blockquote><div><br></div><div>You're subscribing to 'test' from the shell process, not from Pid, so that is why the shell is receiving the message.</div><div><br>
</div><div>-bob</div><div><br></div></div>