Check the other two files in this gist.
In the common.exs
we show a standard approach (by the book) to handle incoming requests via handle_call/3
and {:reply, ...}
return values. It blocks processing of all the coming requests until the one that is handled finished.
In contrast, in the reply.exs
we leverage power of Task.async/1
, GenServer.reply/2
, and {:noreply, ...}
return values. It allows our GenServer process incoming requests in parallel. Then the processing finished, we send results back to the original client (from
pid).
Warning
Be careful, as this approach can lead to uncontrollable load to our GenServer.