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><div><br></div><div>Andrew</div>