Hi all,
I'm proposing a new GenServer callback `query` similar to the call but which does not change the process state.
I find myself writing a lot of `handle_call` callbacks like
def handle_call(request, _from, state) do
...
...
{:reply, result, state}
end
with the `handle_query` this could be written as
def handle_query(request, _from, state) do
...
...
{:reply, result}
end
This is easier to read and write.
A common use case is when you need some computation that depends on the GenServer state. Another is when the GenServer has a side effect and the calls to the server does not changes the actual process state but an external component.
Together with the callback a new GenServer.query function should be implemented which calls the callback on the server context.
I'm not familiar with the internals of the compiler/GenServer but this could also bring optimization opportunities.