is this valid message passing in nitrogen?

7 views
Skip to first unread message

Franklin Brauning

unread,
Apr 27, 2017, 1:01:10 PM4/27/17
to Nitrogen Project / The Nitrogen Web Framework for Erlang
event(ver_estado) ->
        Ref = make_ref(),
        wf:send_global(temporizador, {get_state, self(), Ref}),
        receive
            {Ref, Estado} ->
                wf:update(estado, wf:f("~p", [Estado])),
                wf:flush(),
                ok
        end;

temporizador is a global comet and when receives get_state it delivers data
to the requesting process (in the event function)

but I'm getting this kind of errors (the message content is what the comet delivers)

=WARNING REPORT==== 27-Apr-2017::13:54:06 ===
Unhandled message({#Ref<0.0.3407873.161072>,
                   {#{deadlines => [{<<"sv0nxabg9bjt">>,14827},{reload,36426}],
                      today => "jue"},
                    0}}) to websocket process (<0.23703.0>)

it works the first time ... but then it starts with these warnings

Jesse Gumm

unread,
Apr 28, 2017, 5:42:57 PM4/28/17
to nitrogenweb
Hi Franklin,

So this is combining two different things.  Keep in mind send_global sends that same message to every connected process to that global comet pool, which means you're very likely to get more than one response.  In the case of the "Unhandled Message", that's happening where the websocket process is receiving an unknown message while sitting in a "waiting for something to happen" state.  If there X processes connected to that comet pool, you're going to get X response messages back.

If you need more of a one-off-centralized process to respond, you might want to spin up a gen_server to handle it.

Or if you want something lighter than a gen_server to deal with naked bangs and receives, you could spin up a process using the process_registry_handler (http://nitrogenproject.com/doc/handlers/process_registry.html), which by default uses nprocreg (but could be use gproc).

You can then start or get a pid of a process by doing

{ok, Pid} = process_registry_handler:get_pid(Key, Fun).

Then, if a process named 'Key' is running, it will return the Pid of that process, and if the process named 'Key' is not running, it will start the process with the specified Fun.


--
You received this message because you are subscribed to the Google Groups "Nitrogen Project / The Nitrogen Web Framework for Erlang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nitrogenweb+unsubscribe@googlegroups.com.
To post to this group, send email to nitro...@googlegroups.com.
Visit this group at https://groups.google.com/group/nitrogenweb.
For more options, visit https://groups.google.com/d/optout.



--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm
Reply all
Reply to author
Forward
0 new messages