Skip to content

Commit 90adec0

Browse files
authored
Merge pull request #3 from revelrylabs/bug/timeout-exit
fix: trap timeout exits and turn them into errors
2 parents 0a52090 + fcdb88a commit 90adec0

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ install:
1414
- mix local.hex --force
1515
- mix local.rebar --force
1616
- mix deps.get
17-
- (cd test/js/ && npm install)
17+
- npm install
18+
- cd test/js
19+
- npm install
20+
- cd ../..
1821
script:
1922
- MIX_ENV=test mix coveralls.travis --pro
2023
deploy:

lib/nodejs/supervisor.ex

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,16 @@ defmodule NodeJS.Supervisor do
5151
def call(module, args, opts) when is_tuple(module) and is_list(args) do
5252
timeout = Keyword.get(opts, :timeout, @timeout)
5353

54-
module
55-
|> to_transaction(args, opts)
56-
|> Task.async()
57-
|> Task.await(timeout)
54+
task =
55+
module
56+
|> to_transaction(args, opts)
57+
|> Task.async()
58+
59+
try do
60+
Task.await(task, timeout)
61+
catch
62+
:exit, {:timeout, _} -> {:error, "Call timed out."}
63+
end
5864
end
5965

6066
def call!(module, args \\ [], opts \\ []) do

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule NodeJS.MixProject do
44
def project do
55
[
66
app: :nodejs,
7-
version: "0.2.2",
7+
version: "0.2.3",
88
elixir: "~> 1.6",
99
start_permanent: Mix.env() == :prod,
1010
deps: deps(),

0 commit comments

Comments
 (0)