diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/polyjuice/client.ex | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/polyjuice/client.ex b/lib/polyjuice/client.ex index e0f25d7..618a217 100644 --- a/lib/polyjuice/client.ex +++ b/lib/polyjuice/client.ex @@ -105,6 +105,25 @@ defmodule Polyjuice.Client do GenServer.start(__MODULE__, [base_url, opts]) end + @doc """ + Start the client process and return both the PID and the client struct. + + The return value of this function is compatible with + `DynamicSupervisor.start_child/1`. + """ + @spec start_link_and_get_client(base_url :: String.t(), opts :: Keyword.t()) :: + {:ok, pid, __MODULE__.t()} + def start_link_and_get_client(base_url, opts) do + case start_link(base_url, opts) do + {:ok, pid} -> + client = get_client(pid) + {:ok, pid, client} + + error -> + error + end + end + @impl GenServer def init([base_url, opts]) do base_url = @@ -221,6 +240,7 @@ defmodule Polyjuice.Client do Get a struct that implements `Polyjuice.Client.API` from the pid given by `start/2` or `start_link/2`. """ + @spec get_client(pid :: pid) :: __MODULE__.t() def get_client(pid) do GenServer.call(pid, :get_client) end |