Decouple Comet Pool from Context

Skip to first unread message

Anton Prokofiev

Mar 25, 2021, 3:35:20 AMMar 25
to Nitrogen Project / The Nitrogen Web Framework for Erlang
Hello, Jesse

When  I try to use comet from external process,
to send data to the page:


I got an exception:

** exception error: {badrecord,context}
     in function  wf_context:page_context/0 (src/lib/wf_context.erl, line 300)
     in call from wf_context:series_id/0 (src/lib/wf_context.erl, line 307)
     in call from action_comet:inner_send/3 (src/actions/action_comet.erl, line 635)
     in call from wf:send/2 (src/wf.erl, line 502)

As a result I build a work-around it:

comet_send(PoolType,PoolName,Msg) ->
    Pid  = nprocreg:get_pid({async_pool, {PoolName, PoolType}}),
    case Pid of
        undefined ->  %?LOG(error,"Pool not found: { ~p, ~p}",[PoolName,PoolType]),
        _ -> Pid ! Msg,
This is a hack, knowing how comet register itself in a process register.

It looks like a quite common pattern  for me:

I have gen_server that communicate with external systems (MQTT, and similar),
Then I need to broadcast these data to the html front-end.

At the current set-up I can not do it, as my process is not a part of nitrogen ones (do not have context).

Would be nice to have option send data to comet/subscribe to them from any process.

Another idea: implement functionality similar to gproc_ps,   with publish/subscribe functionality.

Regards, Anton

P.S. I re-implemen gproc_ps for my own needs making it simpler to subscribe using pattern matching.
for example I can do things like:

-record(test_rec, {a,b,c}).

X= #test_rec{a = 1}


that will send all records test_rec where a =1 to subscribers.
All other fields are converted to general matching pattern '_'.

Apr 9, 2021, 2:52:24 AMApr 9
to Nitrogen Project / The Nitrogen Web Framework for Erlang
is there any risk using that comet_send(PoolType,PoolName,Msg) Anton wrote instead of wf:send_global?

I also like the idea of messaging pools from anywhere.

Jesse Gumm

Apr 9, 2021, 8:52:50 AMApr 9
to nitrogenweb
Thanks for the poke on this one - I can't believe I missed this one.

Yes, this is great, and does highlight one of the main limitations of the current comet implementation.

Converting to a pubsub is very high on my to do list. My intent is to treat it like any of the other handlers, where you can plug in your own pubsub if you wanted.


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
To view this discussion on the web visit
Reply all
Reply to author
0 new messages