Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow configuring GenServer timeout for requests #39

Merged
merged 1 commit into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ config :ethereumex,
url: "http://localhost:8545"
```

You can also configure the `GenServer` request timeout for requests sent to the Ethereum JSON-RPC
(you can also overwrite this configuration in `opts` used when calling the client):

```elixir
config :ethereumex,
request_timeout: 10_000 # default is 5000 ms
```

## Usage

### Available methods:
Expand Down
2 changes: 2 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use Mix.Config

config :ethereumex, request_timeout: 5000

import_config "#{Mix.env()}.exs"
3 changes: 2 additions & 1 deletion lib/ethereumex/client/macro.ex
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@ defmodule Ethereumex.Client.Macro do
end

defp server_request(params, opts \\ []) do
GenServer.call(__MODULE__, {:request, params, opts})
timeout = Keyword.get(opts, :request_timeout, Ethereumex.Config.request_timeout())
GenServer.call(__MODULE__, {:request, params, opts}, timeout)
end

def start_link do
Expand Down
5 changes: 5 additions & 0 deletions lib/ethereumex/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ defmodule Ethereumex.Config do
def http_options do
Application.get_env(:ethereumex, :http_options, [])
end

@spec request_timeout() :: integer()
def request_timeout do
Application.get_env(:ethereumex, :request_timeout, 5000)
end
end
6 changes: 5 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ defmodule Ethereumex.Mixfile do
end

def application do
[extra_applications: [:logger], mod: {Ethereumex, []}]
[
env: [request_timeout: 5000],
extra_applications: [:logger],
mod: {Ethereumex, []}
]
end

defp deps do
Expand Down