https://github.com/kr00lix/gen_server_async
GenServerAsync allows to run `.call` method in a separate non-blocking GenServer process.
https://github.com/kr00lix/gen_server_async
elixir elixir-lang gen-server gen-server-async hex
Last synced: 8 days ago
JSON representation
GenServerAsync allows to run `.call` method in a separate non-blocking GenServer process.
- Host: GitHub
- URL: https://github.com/kr00lix/gen_server_async
- Owner: Kr00lIX
- License: mit
- Created: 2018-02-07T07:00:30.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-05-05T10:32:19.000Z (about 6 years ago)
- Last Synced: 2025-02-12T08:24:40.010Z (over 1 year ago)
- Topics: elixir, elixir-lang, gen-server, gen-server-async, hex
- Language: Elixir
- Homepage:
- Size: 26.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# GenServerAsync
-----

[](https://hex.pm/packages/gen_server_async)
[](https://coveralls.io/github/Kr00lIX/gen_server_async?branch=master)
GenServerAsync adds a `call_async` method that allows you to run `GenServer.call/3` 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)` -
```elixir
# 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}
else
# update state and calls `handle_call_async` asynchronously
{:no_reply, updated_state}
end
end
@doc """
"""
def handle_call_async(message, call_state) do
call_async_result = ... # complex calculation
{:reply, call_async_result}
end
# sync GenServer state after handle_call_async if needed
def handle_cast_async(_message, call_async_result, state) do
{:noreply, state}
end
end
```
## Installation
It's available in Hex, the package can be installed as:
Add `gen_server_async` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:gen_server_async, ">= 0.0.1"}]
end
```
Documentation can be found at [https://hexdocs.pm/gen_server_async](https://hexdocs.pm/gen_server_async/).
## License
This software is licensed under [the MIT license](LICENSE.md).