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.

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/4419c19a-8c92-48a5-af4d-f8a0d64112c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to