summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHubert Chathi <hubert@uhoreg.ca>2020-09-19 22:42:26 -0400
committerHubert Chathi <hubert@uhoreg.ca>2020-09-19 22:42:26 -0400
commit67d07c0074aac617f07c1f5764670adad687a58c (patch)
treecbbf55b64c8be8ad6b935317dfb75f92ffa2f6ee
parentstore client opts as a map and drop duplicate data (diff)
add function to return client PID and client struct
-rw-r--r--lib/polyjuice/client.ex20
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