8383Subscribes a web socket client `ws` to `channel`.
8484"""
8585function subscribe (ws:: HTTP.WebSockets.WebSocket , channel:: ChannelName ) :: ChannelClientsCollection
86- # Clean up stale entries from previous connections on this channel so that
87- # disconnected clients (and their handler tasks) do not accumulate on reconnect.
88- unsubscribe_disconnected_clients (channel)
89-
9086 if haskey (CLIENTS, id (ws))
9187 in (channel, CLIENTS[id (ws)]. channels) || push! (CLIENTS[id (ws)]. channels, channel)
9288 else
@@ -95,6 +91,10 @@ function subscribe(ws::HTTP.WebSockets.WebSocket, channel::ChannelName) :: Chann
9591
9692 push_subscription (id (ws), channel)
9793
94+ # Clean up stale entries from previous connections on this channel so that
95+ # disconnected clients (and their handler tasks) do not accumulate on reconnect.
96+ unsubscribe_disconnected_clients (channel)
97+
9898 @debug " Subscribed: $(id (ws)) ($(Dates. now ()) )"
9999 CLIENTS
100100end
@@ -245,10 +245,6 @@ function broadcast(channels::Union{ChannelName,Vector{ChannelName}},
245245
246246 @async unsubscribe_disconnected_clients () |> errormonitor
247247
248- # @show channels
249- # @show CLIENTS
250-
251- # try
252248 for channel in channels
253249 if ! haskey (SUBSCRIPTIONS, channel)
254250 unsubscribe_disconnected_clients (channel)
@@ -276,9 +272,6 @@ function broadcast(channels::Union{ChannelName,Vector{ChannelName}},
276272 end
277273 end
278274 end
279- # catch ex
280- # @warn ex
281- # end
282275
283276 true
284277end
0 commit comments