Skip to content

Commit cdb8592

Browse files
committed
Move PeerConnection initialization to handle_continue
1 parent a98b0ca commit cdb8592

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

.credo.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
# set this value to 0 (zero).
9090
#
9191
{Credo.Check.Design.TagTODO, [exit_status: 0]},
92-
{Credo.Check.Design.TagFIXME, []},
92+
{Credo.Check.Design.TagFIXME, [exit_status: 0]},
9393

9494
#
9595
## Readability Checks

lib/ex_webrtc/peer_connection.ex

+16-1
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,15 @@ defmodule ExWebRTC.PeerConnection do
479479

480480
@impl true
481481
def init(config) do
482+
# FIXME: Spawning a lot of peer connections simultaneously, often takes a lot of time.
483+
# This does not happen when spawning a single peer connection.
484+
# Moving actual initialization to handle_continue at least does not block
485+
# supervisor/dynamic supervisor under which those peer connections are spawned.
486+
{:ok, nil, {:continue, config}}
487+
end
488+
489+
@impl true
490+
def handle_continue(config, _state) do
482491
{:ok, _} = Registry.register(ExWebRTC.Registry, self(), self())
483492

484493
ice_config = [
@@ -533,7 +542,7 @@ defmodule ExWebRTC.PeerConnection do
533542
notify(state.owner, {:connection_state_change, :new})
534543
notify(state.owner, {:signaling_state_change, :stable})
535544

536-
{:ok, state}
545+
{:noreply, state}
537546
end
538547

539548
@impl true
@@ -1376,6 +1385,12 @@ defmodule ExWebRTC.PeerConnection do
13761385
{:noreply, state}
13771386
end
13781387

1388+
@impl true
1389+
def terminate(reason, nil) do
1390+
# we exit before finishing handle_continue
1391+
Logger.debug("Closing peer connection with reason: #{inspect(reason)}")
1392+
end
1393+
13791394
@impl true
13801395
def terminate(reason, state) do
13811396
Logger.debug("Closing peer connection with reason: #{inspect(reason)}")

0 commit comments

Comments
 (0)