Skip to content

Commit

Permalink
Merge pull request jcabotc#3 from salemove/improvements
Browse files Browse the repository at this point in the history
Minor improvements
  • Loading branch information
take-five authored Jul 26, 2017
2 parents a1828de + 6cb89cc commit b79ff81
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 21 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ elixir:
- 1.4.5
otp_release:
- 19.3
- 20.0
script:
- mix test --exclude amqp_server
16 changes: 8 additions & 8 deletions lib/hare/actor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ defmodule Hare.Actor do
{:reply, reply, new_given} ->
{:reply, reply, State.set(state, new_given)}

{:reply, reply, new_given, hibernate} ->
{:reply, reply, State.set(state, new_given), hibernate}
{:reply, reply, new_given, timeout} ->
{:reply, reply, State.set(state, new_given), timeout}

{:noreply, new_given} ->
{:noreply, State.set(state, new_given)}

{:noreply, new_given, hibernate} ->
{:noreply, State.set(state, new_given), hibernate}
{:noreply, new_given, timeout} ->
{:noreply, State.set(state, new_given), timeout}

{:stop, reason, reply, new_given} ->
{:stop, reason, reply, State.set(state, new_given)}
Expand All @@ -165,8 +165,8 @@ defmodule Hare.Actor do
{:noreply, new_given} ->
{:noreply, State.set(state, new_given)}

{:noreply, new_given, hibernate} ->
{:noreply, State.set(state, new_given), hibernate}
{:noreply, new_given, timeout} ->
{:noreply, State.set(state, new_given), timeout}

{:stop, reason, new_given} ->
{:stop, reason, State.set(state, new_given)}
Expand All @@ -188,8 +188,8 @@ defmodule Hare.Actor do
{:noreply, new_given} ->
{:noreply, State.set(state, new_given)}

{:noreply, new_given, hibernate} ->
{:noreply, State.set(state, new_given), hibernate}
{:noreply, new_given, timeout} ->
{:noreply, State.set(state, new_given), timeout}

{:stop, reason, new_given} ->
{:stop, reason, State.set(state, new_given)}
Expand Down
4 changes: 4 additions & 0 deletions lib/hare/adapter/sandbox/chan.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ defmodule Hare.Adapter.Sandbox.Chan do
alias __MODULE__.Pid
alias Hare.Adapter.Sandbox.Conn

@type t :: %Chan{
pid: pid,
conn: Conn.t}

defstruct [:pid, :conn]

def open(%Conn{} = conn) do
Expand Down
5 changes: 5 additions & 0 deletions lib/hare/adapter/sandbox/conn.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ defmodule Hare.Adapter.Sandbox.Conn do
alias __MODULE__
alias __MODULE__.{Pid, History, Stack}

@type t :: %Conn{pid: pid,
history: GenServer.server,
on_channel_open: GenServer.server,
messages: list}

defstruct [:pid, :history, :on_channel_open, :messages]

def open(config) do
Expand Down
4 changes: 2 additions & 2 deletions lib/hare/core/conn.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ defmodule Hare.Core.Conn do
By default the timeout is 5 seconds.
"""

@type config :: State.Bridge.config

use Connection

alias __MODULE__.State

@type config :: State.Bridge.config

@doc """
Starts a `Hare.Core.Conn` process linked to the current process.
Expand Down
3 changes: 2 additions & 1 deletion lib/hare/core/conn/state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ defmodule Hare.Core.Conn.State do
reply.(client, {:ok, Chan.new(given_chan, bridge.adapter)})
state
end
defp handle_open_channel(:not_connected, %{waiting: waiting} = state, client) do
defp handle_open_channel(reason, %{waiting: waiting} = state, client)
when reason in [:not_connected, :closing, :blocked] do
%{state | waiting: Waiting.push(waiting, client)}
end
defp handle_open_channel({:error, _reason} = error, %{reply: reply} = state, client) do
Expand Down
46 changes: 38 additions & 8 deletions lib/hare/rpc/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ defmodule Hare.RPC.Client do
"""
@callback handle_connected(state) ::
{:noreply, state} |
{:noreply, state, timeout | :hibernate} |
{:stop, reason :: term, state}

@doc """
Expand Down Expand Up @@ -129,6 +130,7 @@ defmodule Hare.RPC.Client do
"""
@callback handle_disconnected(reason :: term, state) ::
{:noreply, state} |
{:noreply, state, timeout | :hibernate} |
{:stop, reason :: term, state}

@doc """
Expand All @@ -146,10 +148,14 @@ defmodule Hare.RPC.Client do
ones, block the client until the response is received, and enter
the main loop with the given state.
Returning `{:reply, response, state}` will respond the client inmediately
Returning `{:reply, reply, state}` will respond the client inmediately
without performing the request with the given response, and enter the main
loop again with the given state.
Returning `{:reply, reply, state, timeout}` is similar to `{:reply, reply, state}`
except `handle_info(:timeout, state)` will be called after `timeout` milliseconds
if no messages are received.
Returning `{:stop, reason, response, state}` will not send the message,
respond to the caller with `response`, and terminate the main loop
and call `terminate(reason, state)` before the process exits with
Expand All @@ -163,6 +169,7 @@ defmodule Hare.RPC.Client do
{:ok, state} |
{:ok, payload, routing_key, opts :: term, state} |
{:reply, response, state} |
{:reply, response, state, timeout | :hibernate} |
{:stop, reason :: term, response, state} |
{:stop, reason :: term, state}

Expand All @@ -176,10 +183,18 @@ defmodule Hare.RPC.Client do
delivered to the caller instead of the original response, and enter
the main loop with the given state.
Returning `{:reply, reply, state, timeout}` is similar to `{:reply, reply, state}`
except `handle_info(:timeout, state)` will be called after timeout milliseconds
if no messages are received.
Returning `{:noreply, state}` will enter the main loop with the given state
without responding to the caller (that will eventually timeout or keep blocked
forever if the timeout was set to `:infinity`).
Returning `{:noreply, state, timeout}` is similar to `{:noreply, state}` except
`handle_info(:timeout, state)` will be called after timeout milliseconds if no
messages are received.
Returning `{:stop, reason, reply, state}` will deliver the given reply to
the caller instead of the original response and call `terminate(reason, state)`
before the process exits with reason `reason`.
Expand All @@ -189,7 +204,9 @@ defmodule Hare.RPC.Client do
"""
@callback on_response(response, from, state) ::
{:reply, response, state} |
{:reply, response, state, timeout | :hibernate} |
{:noreply, state} |
{:noreply, state, timeout | :hibernate} |
{:stop, reason :: term, response, state} |
{:stop, reason :: term, state}

Expand All @@ -216,7 +233,9 @@ defmodule Hare.RPC.Client do
"""
@callback on_return(payload, state) ::
{:reply, response, state} |
{:reply, response, state, timeout | :hibernate} |
{:noreply, state} |
{:noreply, state, timeout | :hibernate} |
{:stop, reason :: term, response, state} |
{:stop, reason :: term, state}

Expand All @@ -242,14 +261,18 @@ defmodule Hare.RPC.Client do
"""
@callback on_timeout(from, state) ::
{:reply, response, state} |
{:reply, response, state, timeout | :hibernate} |
{:noreply, state} |
{:noreply, state, timeout | :hibernate} |
{:stop, reason :: term, response, state} |
{:stop, reason :: term, state}

@doc """
Called when the process receives a call message sent by `call/3`. This
callback has the same arguments as the `GenServer` equivalent and the
`:reply`, `:noreply` and `:stop` return tuples behave the same.
See `c:GenServer.handle_call/3`.
"""
@callback handle_call(request :: term, GenServer.from, state) ::
{:reply, reply :: term, state} |
Expand All @@ -263,24 +286,24 @@ defmodule Hare.RPC.Client do
Called when the process receives a cast message sent by `cast/3`. This
callback has the same arguments as the `GenServer` equivalent and the
`:noreply` and `:stop` return tuples behave the same.
See `c:GenServer.handle_cast/2`.
"""
@callback handle_cast(request :: term, state) ::
{:noreply, state} |
{:noreply, state, timeout | :hibernate} |
{:stop, reason :: term, state}

@doc """
Called when the process receives a message.
Returning `{:noreply, state}` will causes the process to enter the main loop
with the given state.
Called when the process receives a message. This callback has the same
arguments as the `GenServer` equivalent and the `:noreply` and `:stop`
return tuples behave the same.
Returning `{:stop, reason, state}` will not send the message, terminate the
main loop and call `terminate(reason, state)` before the process exits with
reason `reason`.
See `c:GenServer.handle_info/2`.
"""
@callback handle_info(meta, state) ::
{:noreply, state} |
{:noreply, state, timeout | :hibernate} |
{:stop, reason :: term, state}

@doc """
Expand Down Expand Up @@ -629,9 +652,16 @@ defmodule Hare.RPC.Client do
GenServer.reply(from, response)
{:noreply, State.set(state, new_given)}

{:reply, response, new_given, timeout} ->
GenServer.reply(from, response)
{:noreply, State.set(state, new_given), timeout}

{:noreply, new_given} ->
{:noreply, State.set(state, new_given)}

{:noreply, new_given, timeout} ->
{:noreply, State.set(state, new_given), timeout}

{:stop, reason, response, new_given} ->
GenServer.reply(from, response)
{:stop, reason, State.set(state, new_given)}
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Hare.Mixfile do

def project do
[app: :hare,
version: "0.2.0",
version: "0.2.1",
elixir: "~> 1.4",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
Expand All @@ -12,7 +12,7 @@ defmodule Hare.Mixfile do
deps: deps(),
dialyzer: [
flags: [:error_handling],
remove_defaults: [:unknown]]
plt_add_apps: [:amqp]]
]
end

Expand Down

0 comments on commit b79ff81

Please sign in to comment.