Skip to content

Commit 0319bfc

Browse files
committed
Don't use global timer for client ping loop.
1 parent 418a645 commit 0319bfc

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

lib/slack/real_time/concurrency/async.rb

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ module Slack
55
module RealTime
66
module Concurrency
77
module Async
8-
class Reactor < ::Async::Reactor
9-
def_delegators :@timers, :cancel
10-
end
11-
128
class Client < ::Async::WebSocket::Client
139
extend ::Forwardable
1410
def_delegators :@driver, :on, :text, :binary, :emit
@@ -18,15 +14,23 @@ class Socket < Slack::RealTime::Socket
1814
attr_reader :client
1915

2016
def start_async(client)
21-
@reactor = Reactor.new
17+
@reactor = ::Async::Reactor.new
18+
2219
Thread.new do
23-
if client.run_ping?
24-
@reactor.every(client.websocket_ping) do
25-
client.run_ping!
26-
end
27-
end
2820
@reactor.run do |task|
29-
task.async do
21+
if client.run_ping?
22+
task.async do |subtask|
23+
subtask.annotate "client keep-alive"
24+
25+
while true
26+
subtask.sleep client.websocket_ping
27+
client.run_ping!
28+
end
29+
end
30+
end
31+
32+
task.async do |subtask|
33+
subtask.annotate "client run-loop"
3034
client.run_loop
3135
end
3236
end
@@ -52,13 +56,6 @@ def connect!
5256
run_loop
5357
end
5458

55-
# Send a close event and stop the reactor.
56-
def disconnect!
57-
@reactor.cancel
58-
super
59-
close
60-
end
61-
6259
# Close the socket.
6360
def close
6461
@socket.close if @socket

0 commit comments

Comments
 (0)