pkamenarsky / concur-replica

Server-side VDOM UI framework for Concur
BSD 3-Clause "New" or "Revised" License
139 stars 20 forks source link

PubSub and/or Init + Terminate callbacks #42

Closed 21it closed 4 years ago

21it commented 4 years ago

Hello @pkamenarsky! First of all, thanks for great library, I'm really enjoying it! Special thanks for examples which are working!

I see you might be pretty familiar with Erlang/OTP/Phoenix because you mentioned LiveView library in readme file. I have a question, does this library have something similar to Phoenix.PubSub? Or just Erlang pg2 - to have a groups of Replica processes currently running, which I want to be able to receive notifications of some events happened outside of Replica (DB entity updates, API notifications received, literally any kind of external IO)

The second question - is there and kind of callbacks similar to Erlang GenServer init and terminate for Replica processes? Init is supposed to be applied when client connects and Replica process is spawned, terminate is applied when client disconnects. If we have these callbacks then I think it will be possible to build PubSub - like things on top of it with MVars or STM.

I need this some kind of PubSub and process Registry for my app, and it's possible to do registry based on process ids, but without terminate callback memory will leak - I need to cleanup state from already disconnected/dead processes somehow. In Erlang I guess it's usually done with monitor function, and I'm sure it's Erlang-specific thing. If there is similar function for general Haskell processes including Replica processes - it might solve the issue as well.

21it commented 4 years ago

I found that STM TChan is solved this issue for now

pkamenarsky commented 4 years ago

Sorry for the late reply - yes, PubSub should be relatively easy to achieve with the standard Haskell concurrency primitives without leaking memory.

The second question - is there and kind of callbacks similar to Erlang GenServer init and terminate for Replica processes? Init is supposed to be applied when client connects and Replica process is spawned, terminate is applied when client disconnects. If we have these callbacks then I think it will be possible to build PubSub - like things on top of it with MVars or STM.

This shouldn't be too hard to implement, but I gather you don't need this anymore, since TMChans are automatically garbage collected when a client disconnects.