Skip to content

Commit

Permalink
#16 Implement customizable timeouts for calls
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewvy committed Sep 19, 2018
1 parent 56adcb6 commit 1f0629a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/page_session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,16 @@ defmodule ChromeRemoteInterface.PageSession do
`:async` -
If a boolean, sends the response as a message to the current process.
Else, if provided with a PID, it will send the response to that process instead.
`:timeout` -
This sets the timeout for the blocking call, defaults to 5 seconds.
"""
def execute_command(pid, method, params, opts) do
async = Keyword.get(opts, :async, false)
timeout = Keyword.get(opts, :timeout, 5_000)

case async do
false -> call(pid, method, params)
false -> call(pid, method, params, timeout)
true -> cast(pid, method, params, self())
from when is_pid(from) -> cast(pid, method, params, from)
end
Expand All @@ -99,8 +103,8 @@ defmodule ChromeRemoteInterface.PageSession do
@doc """
Executes a raw JSON RPC command through Websockets.
"""
def call(pid, method, params) do
GenServer.call(pid, {:call_command, method, params})
def call(pid, method, params, timeout) do
GenServer.call(pid, {:call_command, method, params}, timeout)
end

@doc """
Expand Down

0 comments on commit 1f0629a

Please sign in to comment.