File tree Expand file tree Collapse file tree 1 file changed +24
-17
lines changed
lib/slack/real_time/concurrency Expand file tree Collapse file tree 1 file changed +24
-17
lines changed Original file line number Diff line number Diff line change @@ -13,25 +13,28 @@ class Client < ::Async::WebSocket::Client
1313 class Socket < Slack ::RealTime ::Socket
1414 attr_reader :client
1515
16- def start_async ( client )
17- @reactor = ::Async ::Reactor . new
16+ def start_sync ( client )
17+ start_reactor ( client ) . wait
18+ end
1819
20+ def start_async ( client )
1921 Thread . new do
20- @reactor . run do |task |
21- if client . run_ping?
22- task . async do |subtask |
23- subtask . annotate 'client keep-alive'
24-
25- loop do
26- subtask . sleep client . websocket_ping
27- client . run_ping!
28- end
29- end
30- end
22+ start_reactor ( client )
23+ end
24+ end
25+
26+ def start_reactor ( client )
27+ Async do |task |
28+ self . restart_async ( client , @url )
3129
30+ if client . run_ping?
3231 task . async do |subtask |
33- subtask . annotate 'client run-loop'
34- client . run_loop
32+ subtask . annotate 'client keep-alive'
33+
34+ while true
35+ subtask . sleep client . websocket_ping
36+ run_ping!
37+ end
3538 end
3639 end
3740 end
@@ -40,9 +43,13 @@ def start_async(client)
4043 def restart_async ( client , new_url )
4144 @url = new_url
4245 @last_message_at = current_time
43- return unless @reactor
4446
45- @reactor . async do
47+ if @client_task
48+ @client_task . stop
49+ end
50+
51+ @client_task = task . async do |subtask |
52+ subtask . annotate 'client run-loop'
4653 client . run_loop
4754 end
4855 end
You can’t perform that action at this time.
0 commit comments