5 ms·
`gen_server` is an abstraction over the a client sending a `request` that a server services to produce a `response` to be sent to the client. The `gen_server`
by asabil 1y ago
`gen_server` is an abstraction over the a client sending a `request` that a server services to produce a `response` to be sent to the client.
The `gen_server` implementation takes care of things like timeouts, servers terminating before a response is produced as well as maintaining the server state.
You can read more here at [1], [2] and [3].
[1]: https://learnyousomeerlang.com/clients-and-servers#callback-to-the-future https://learnyousomeerlang.com/clients-and-servers#callback-...
[2]: https://www.erlang.org/doc/system/gen_server_concepts https://www.erlang.org/doc/system/gen_server_concepts
[3]: https://www.erlang.org/doc/apps/stdlib/gen_server.html https://www.erlang.org/doc/apps/stdlib/gen_server.html
- vector_spaces 1y agoI'll add to this that the "abstraction" component of this description is key and the use-case for a gen_server is far more broad than what you might expect in say a networking or web context. You would use them for instance when you need to group behavioral units with a defined interface, even if you don't require any explicit networking. This is a bit reductive and wrong in some ways but think of gen_server modules and instances as "sort of" like classes/objects. You "send messages/requests" instead of "calling methods," but the spirit is essentially the same -- it's a way of modeling the world with code
- skeledrew 1y ago> You "send messages/requests" instead of "calling methods," Sounds like Smalltalk.
- igouy 1y ago"Computing should be viewed as an intrinsic capability of objects that can be uniformly invoked by sending messages." p 290 1981 "Design Principles Behind Smalltalk" https://archive.org/details/byte-magazine-1981-08/page/n298/mode/1up https://archive.org/details/byte-magazine-1981-08/page/n298/...