Have you evaluated an Agent for your purposes? It has basically exactly 
this function.

On Tuesday, January 30, 2018 at 9:17:08 AM UTC-5, Federico Bergero wrote:
>
> 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/249e8c65-c2a2-4cbc-9956-1868d68b022f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to