Class: Slack::RealTime::Concurrency::Async::Socket
- Inherits:
-
Socket
- Object
- Socket
- Slack::RealTime::Concurrency::Async::Socket
show all
- Defined in:
- lib/slack/real_time/concurrency/async.rb
Instance Attribute Summary collapse
Attributes inherited from Socket
#driver, #options, #url
Instance Method Summary
collapse
Methods inherited from Socket
#connected?, #initialize, #send_data, #time_since_last_message
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
16
17
18
|
# File 'lib/slack/real_time/concurrency/async.rb', line 16
def client
@client
end
|
Instance Method Details
#close ⇒ Object
94
95
96
97
98
99
100
101
|
# File 'lib/slack/real_time/concurrency/async.rb', line 94
def close
super
ensure
if @socket
@socket.close
@socket = nil
end
end
|
#connect! ⇒ Object
78
79
80
81
|
# File 'lib/slack/real_time/concurrency/async.rb', line 78
def connect!
super
run_loop
end
|
#current_time ⇒ Object
74
75
76
|
# File 'lib/slack/real_time/concurrency/async.rb', line 74
def current_time
::Async::Clock.now
end
|
#disconnect! ⇒ Object
Kill the restart/ping loop.
84
85
86
87
88
89
90
91
|
# File 'lib/slack/real_time/concurrency/async.rb', line 84
def disconnect!
super
ensure
if (restart = @restart)
@restart = nil
restart.signal
end
end
|
#restart_async(_client, new_url) ⇒ Object
63
64
65
66
67
68
|
# File 'lib/slack/real_time/concurrency/async.rb', line 63
def restart_async(_client, new_url)
@url = new_url
@last_message_at = current_time
@restart&.signal
end
|
#run_async(&block) ⇒ Object
70
71
72
|
# File 'lib/slack/real_time/concurrency/async.rb', line 70
def run_async(&block)
::Async.run(&block)
end
|
#run_loop ⇒ Object
103
104
105
106
107
|
# File 'lib/slack/real_time/concurrency/async.rb', line 103
def run_loop
while @driver&.next_event
end
end
|
#start_async(client) ⇒ Object
22
23
24
25
26
|
# File 'lib/slack/real_time/concurrency/async.rb', line 22
def start_async(client)
Thread.new do
start_reactor(client)
end
end
|
#start_reactor(client) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/slack/real_time/concurrency/async.rb', line 28
def start_reactor(client)
Async do |task|
@restart = ::Async::Notification.new
if client.run_ping?
@ping_task = task.async do |subtask|
subtask.annotate "#{client} keep-alive"
while @restart
subtask.sleep client.websocket_ping_timer
client.run_ping! if @restart
end
end
end
while @restart
@client_task&.stop
@client_task = task.async do |subtask|
subtask.annotate "#{client} run-loop"
client.run_loop
rescue ::Async::Wrapper::Cancelled => e
rescue StandardError => e
client.logger.error(subtask.to_s) { e.message }
end
@restart.wait
end
@ping_task&.stop
end
end
|
#start_sync(client) ⇒ Object
18
19
20
|
# File 'lib/slack/real_time/concurrency/async.rb', line 18
def start_sync(client)
start_reactor(client).wait
end
|