11const subscription_tracker = Ref {Dict} (Dict ())
22
3- function writews (ws:: HTTP.WebSockets.WebSocket , msg)
4- if isdefined (HTTP, :send )
5- HTTP. send (ws, msg)
6- else
7- write (ws, msg)
8- end
9- end
10-
11- function writews (ws:: IO , msg)
12- write (ws, msg)
13- end
14-
153"""
164 open_subscription(fn::Function,
175 [client::Client],
@@ -109,7 +97,7 @@ function open_subscription(fn::Function,
10997 HTTP. WebSockets. open (client. ws_endpoint; retry= retry, headers= client. headers, suppress_close_error= false ) do ws
11098 # Start sub
11199 output_info (verbose) && println (" Starting $(get_name (subscription_name)) subscription with ID $sub_id " )
112- writews (ws, message_str)
100+ HTTP . send (ws, message_str)
113101 subscription_tracker[][sub_id] = " open"
114102
115103 # Init function
@@ -170,24 +158,6 @@ function clear_subscriptions()
170158 end
171159end
172160
173- function async_reader_with_timeout (io:: IO , subtimeout):: Channel
174- ch = Channel (1 )
175- task = @async begin
176- reader_task = current_task ()
177- function timeout_cb (timer)
178- put! (ch, :timeout )
179- Base. throwto (reader_task, InterruptException ())
180- end
181- timeout = Timer (timeout_cb, subtimeout)
182- data = readavailable (io)
183- subtimeout > 0 && close (timeout) # Cancel the timeout
184- put! (ch, data)
185- end
186- bind (ch, task)
187- return ch
188- end
189-
190-
191161function async_reader_with_timeout (ws:: HTTP.WebSocket , subtimeout):: Channel
192162 ch = Channel (1 )
193163 task = @async begin
@@ -205,28 +175,6 @@ function async_reader_with_timeout(ws::HTTP.WebSocket, subtimeout)::Channel
205175 return ch
206176end
207177
208-
209- function async_reader_with_stopfn (io:: IO , stopfn, checktime):: Channel
210- ch = Channel (1 ) # Could we make this channel concretely typed?
211- task = @async begin
212- reader_task = current_task ()
213- function timeout_cb (timer)
214- if stopfn ()
215- put! (ch, :stopfn )
216- Base. throwto (reader_task, InterruptException ())
217- else
218- timeout = Timer (timeout_cb, checktime)
219- end
220- end
221- timeout = Timer (timeout_cb, checktime)
222- data = readavailable (io)
223- close (timeout) # Cancel the timeout
224- put! (ch, data)
225- end
226- bind (ch, task)
227- return ch
228- end
229-
230178function async_reader_with_stopfn (ws:: HTTP.WebSockets.WebSocket , stopfn, checktime):: Channel
231179 ch = Channel (1 ) # Could we make this channel concretely typed?
232180 task = @async begin
@@ -265,20 +213,6 @@ A channel is returned with the data. If `stopfn` stops the websocket,
265213the data will be `:stopfn`. If the timeout stops the websocket,
266214the data will be `:timeout`
267215"""
268- function readfromwebsocket (ws:: IO , stopfn, subtimeout)
269- if isnothing (stopfn) && subtimeout > 0
270- ch_out = async_reader_with_timeout (ws, subtimeout)
271- data = take! (ch_out)
272- elseif ! isnothing (stopfn)
273- checktime = subtimeout > 0 ? subtimeout : 2
274- ch_out = async_reader_with_stopfn (ws, stopfn, checktime)
275- data = take! (ch_out)
276- else
277- data = readavailable (ws)
278- end
279- return data
280- end
281-
282216function readfromwebsocket (ws:: HTTP.WebSockets.WebSocket , stopfn, subtimeout)
283217 if isnothing (stopfn) && subtimeout > 0
284218 ch_out = async_reader_with_timeout (ws, subtimeout)
@@ -291,4 +225,4 @@ function readfromwebsocket(ws::HTTP.WebSockets.WebSocket, stopfn, subtimeout)
291225 data = HTTP. receive (ws)
292226 end
293227 return data
294- end
228+ end
0 commit comments