# GenServerAsync 
[![Build Status](](
[![Hex pm](](
[![Coverage Status](](

GenServerAsync adds a `call_async` method that allows you to run `` method in a separate non-blocking GenServer process.

Extends the GenServer behavior, adds a `.call_async(server_pid, message)` method to it, which allows you to divide the blocking `handle_call` into three callbacks.
`handle_call(message, from, state)` –

`handle_call_async(message, call_state)` – asynchronously call this

`handle_cast_async(message, call_async_result, state)` - 

# Start the server
{:ok, pid} = GenServerAsync.start_link(ExampleServer, state)
GenServerAsync.call_async(pid, message)

defmodule ExampleServer do
  use GenServerAsync

  # Makes a synchronous call to the server and waits for its reply.
  def handle_call(message, from, state) do
    if could_reply_immediately?(message) do
      {:reply, response, updated_state}

      # update state and calls `handle_call_async` asynchronously
      {:no_reply, updated_state}

  @doc """

  def handle_call_async(message, call_state) do
    call_async_result = ... # complex  calculation
    {:reply, call_async_result}

  # sync GenServer state after handle_call_async if needed
  def handle_cast_async(_message, call_async_result, state) do
    {:noreply, state}

## Installation
It's available in Hex, the package can be installed as:
Add `gen_server_async` to your list of dependencies in `mix.exs`:

def deps do
  [{:gen_server_async, ">= 0.0.1"}]

Documentation can be found at [](

## License
This software is licensed under [the MIT license](