Thanks for those thoughts Whossname! I’d never heard of
:timer.apply_interval/4, that looks like it could have some interesting use for recurring background tasks.
One of the things I love about the GenServer solution is that you don’t have to worry about supervision other than adding the worker to your
application.ex, even though it wouldn’t be difficult to put supervision around a simple
:timer.apply_interval it would be something you would need to understand and implement.
Appreciate your thoughts on using GenServers as a way to manage state surrounding channels! I haven’t been on a project yet where I needed channels in a raw form that wasn’t abstracted by Absinthe-Phoenix or LiveView yet, so those are great cases to keep in mind if I find myself in that position.
The cases you mentioned drive the point though: GenServer tends to be the right abstraction for lower level concerns (channel state and reconnect management) that most web devs working on most mundane web dev tasks don’t really need to worry about. When you do run into those cases, it’s time to roll up your sleeves and fundamentally understand the tool so you can use it correctly.