Skip to content

Commit 1eb04d2

Browse files
committed
fix: Wait for socket init
1 parent cdae88a commit 1eb04d2

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

‎lib/octocon_web/user_socket.ex‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,9 @@ defmodule OctoconWeb.UserChannel do
8080
exceeds_ios_limit = :erlang.external_size(init_data) * 1.1 > 1_048_576
8181

8282
if exceeds_ios_limit && version >= @batched_init_version do
83-
spawn(fn ->
84-
# TODO: Necessary delay?
85-
Process.sleep(50)
86-
send_batched_init(socket, init_data)
87-
end)
83+
send(self(), :send_batched_init)
8884

89-
{:ok, %{@batched_dummy_response | system: init_data["system"]}, socket}
85+
{:ok, %{@batched_dummy_response | system: init_data["system"]}, socket |> assign(:init_data, init_data)}
9086
else
9187
Process.send_after(socket.transport_pid, :garbage_collect, :timer.seconds(1))
9288
{:ok, init_data, socket}
@@ -210,6 +206,16 @@ defmodule OctoconWeb.UserChannel do
210206
@impl true
211207
def handle_info({:plug_conn, :sent}, socket), do: {:noreply, socket}
212208

209+
def handle_info(:send_batched_init, socket) do
210+
init_data = socket.assigns[:init_data]
211+
212+
if init_data do
213+
send_batched_init(socket, init_data)
214+
end
215+
216+
{:noreply, socket |> assign(:init_data, nil)}
217+
end
218+
213219
defp encode_response(conn) do
214220
%{
215221
"status" => conn.status,

0 commit comments

Comments
 (0)