3 ms·
I use other people's GenServers. Never agents. Tasks for concurrency (but almost never those either, just Oban). Ets for stateful datastore. Pedantically I
by throwawaymaths 3y ago
I use other people's GenServers. Never agents. Tasks for concurrency (but almost never those either, just Oban). Ets for stateful datastore.
Pedantically I guess gen_statem isn't a genServer, but I'm generally referring to the pattern, which gen_statem is.
Mostly webdev, so, that stuff is all taken care of for me.
MBTA is modeling reactive systems that exist in the real world, so yeah, that's a place where i would be surprised if you didn't use genservers, though I suppose you could just use a database-backed state machine. Surprised you use GenServers instead of gen_statem (though you might have been, as I was, less than pedantic)
- AlchemistCamp 3y agoAre you actively trying not to use GenServers in your application code or is it just that you have a set of 3rd party dependencies that remove the need?
- throwawaymaths 3y agoYes
- jolux 3y agoAh I see. Yeah, Phoenix definitely gives you a lot out of the box. I think for webdev it's probably enough. This is a pretty straightforward Phoenix app for example, only uses a couple GenServers: https://github.com/mbta/arrow https://github.com/mbta/arrow The question of when to introduce databases is a really interesting one and also one I'm still coming to terms with a few years into writing Elixir full-time. Many of our apps don't use them at all, but I think at least a few could benefit from more structure and durability in their datastores.
- jolux 3y agoI see after I posted you edited to mention Agents, Tasks, Oban, and gen_statem. What do you use gen_statem for? I'll admit its intended use-case has always seemed pretty narrow to me, but maybe I just don't understand it very well.
- throwawaymaths 3y agoI don't use gen_statem, its clunky as hell, does a weird thing with response aliasing, and it's even harder to read than Genserver. Plus I don't need it. I understand why the callbacks in gen_statem are so messed up though, they want you to be able to organize your code by state. Since Erlang and (weakly) elixir requires you to group handle_x callbacks linearly in the module, you can't group by state unless you have a `handle_anything`. It's all so messed up :(