Skip to content

Commit 9c58f9c

Browse files
mrmicahcooperMicah CoopersleipnirMicah Cooper
authored
Ensure 1 GRPC.Client.Supervisor (#466)
* Ensure 1 GRPC.Client.Supervisor * Update lib/grpc/client/supervisor.ex * Format code - verify author --------- Co-authored-by: Micah Cooper <micah.cooper@mimic.com> Co-authored-by: Adriano Santos <solid.sistemas@gmail.com> Co-authored-by: Micah Cooper <mrmichacooper@gmail.com>
1 parent c342db0 commit 9c58f9c

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/grpc/client/supervisor.ex

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,16 @@ defmodule GRPC.Client.Supervisor do
4444
use DynamicSupervisor
4545

4646
def start_link(opts) do
47-
DynamicSupervisor.start_link(__MODULE__, opts, name: __MODULE__)
47+
case DynamicSupervisor.start_link(__MODULE__, opts, name: __MODULE__) do
48+
{:ok, _pid} = started ->
49+
started
50+
51+
{:error, {:already_started, pid}} ->
52+
{:ok, pid}
53+
54+
other ->
55+
other
56+
end
4857
end
4958

5059
@impl true
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
defmodule GRPC.Client.SupervisorTest do
2+
use ExUnit.Case, async: false
3+
4+
alias GRPC.Client
5+
6+
describe "start_link/1" do
7+
test "allows multiple start_links" do
8+
{:ok, second_pid} = Client.Supervisor.start_link([])
9+
{:ok, third_pid} = Client.Supervisor.start_link([])
10+
11+
assert second_pid == third_pid
12+
end
13+
end
14+
end

0 commit comments

Comments
 (0)