Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shun159/gen_batch_server_ex
wrapper for rabbitmq/gen-batch-server
https://github.com/shun159/gen_batch_server_ex
Last synced: 9 days ago
JSON representation
wrapper for rabbitmq/gen-batch-server
- Host: GitHub
- URL: https://github.com/shun159/gen_batch_server_ex
- Owner: shun159
- Created: 2019-09-24T11:34:12.000Z (over 5 years ago)
- Default Branch: develop
- Last Pushed: 2019-09-25T07:58:20.000Z (over 5 years ago)
- Last Synced: 2024-12-20T11:32:44.839Z (19 days ago)
- Language: Elixir
- Size: 16.6 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GenBatchServer
Elixir wrapper of `rabbitmq/gen-batch-server`
usage:
```elixir
defmodule Stack do
@moduledoc """
Example for a very simple-minded Stack server
"""use GenBatchServer
def push(element) do
GenBatchServer.cast(__MODULE__, {:push, element})
enddef pop do
GenBatchServer.call(__MODULE__, :pop)
end@spec start_link() :: GenBatchServer.on_start()
def start_link do
GenBatchServer.start_link(__MODULE__, [:hello], name: __MODULE__)
end@impl GenBatchServer
def init(stack) do
{:ok, stack}
end@impl GenBatchServer
def handle_batch(commands, state) do
handle_commands([], commands, state)
end# private functions
defp handle_commands(actions, [], state),
do: {:ok, actions, state}defp handle_commands(actions, [command | rest], state) do
case command do
{:cast, {:push, element}} ->
handle_commands(actions, rest, [element | state]){:call, from, :pop} ->
action = {:reply, from, hd(state)}
handle_commands([action | actions], rest, tl(state))
end
end
end
```