gen_server_async v0.0.1 GenServerAsync behaviour
Gen server with no blocking calls
Usage
defmodule Queue do
use GenServerAsync
def register(pid, user) do
GenServerAsync.call_async(pid, {:register, user})
end
# blocking call
def handle_call({:register, user}, from, state) do
with :not_found <- found_user(state, user) do
# call async callback
{:noreply, state}
else
{:found, user} ->
# send reply to call
{:reply, {:alredy_registered, user}, state}
end
end
# called async
def handle_call_async({:register, user}, from, state) do
result = heavy_function(user)
{:reply, result, state}
end
# called on finish `handle_call_async` with result
def handle_cast_async({:register, user}, result, state) do
# update state if needed
{:noreply, state}
end
end
Link to this section Summary
Link to this section Types
Link to this section Functions
Link to this function
call(server, message, timeout \\ 5000)
Link to this function
call_async(pid, message, opts \\ [])
Link to this function
start_link(module, args, options \\ [])
Link to this section Callbacks
Link to this callback
handle_call_async(message, state)
Link to this callback
handle_cast_async(message, result, state)