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.
15
16
17
|
# File 'lib/slack/real_time/concurrency/async.rb', line 15
def client
@client
end
|
Instance Method Details
#close ⇒ Object
91
92
93
94
95
96
97
98
|
# File 'lib/slack/real_time/concurrency/async.rb', line 91
def close
super
ensure
if @socket
@socket.close
@socket = nil
end
end
|
#connect! ⇒ Object
75
76
77
78
|
# File 'lib/slack/real_time/concurrency/async.rb', line 75
def connect!
super
run_loop
end
|
#current_time ⇒ Object
71
72
73
|
# File 'lib/slack/real_time/concurrency/async.rb', line 71
def current_time
::Async::Clock.now
end
|
#disconnect! ⇒ Object
Kill the restart/ping loop.
81
82
83
84
85
86
87
88
|
# File 'lib/slack/real_time/concurrency/async.rb', line 81
def disconnect!
super
ensure
if restart = @restart
@restart = nil
restart.signal
end
end
|
#restart_async(_client, new_url) ⇒ Object
64
65
66
67
68
69
|
# File 'lib/slack/real_time/concurrency/async.rb', line 64
def restart_async(_client, new_url)
@url = new_url
@last_message_at = current_time
@restart.signal if @restart
end
|
#run_loop ⇒ Object
100
101
102
103
104
|
# File 'lib/slack/real_time/concurrency/async.rb', line 100
def run_loop
while @driver && @driver.next_event
end
end
|
#start_async(client) ⇒ Object
21
22
23
24
25
|
# File 'lib/slack/real_time/concurrency/async.rb', line 21
def start_async(client)
Thread.new do
start_reactor(client)
end
end
|
#start_reactor(client) ⇒ Object
27
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
62
|
# File 'lib/slack/real_time/concurrency/async.rb', line 27
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 if @client_task
@client_task = task.async do |subtask|
begin
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
end
@restart.wait
end
@ping_task.stop if @ping_task
end
end
|
#start_sync(client) ⇒ Object
17
18
19
|
# File 'lib/slack/real_time/concurrency/async.rb', line 17
def start_sync(client)
start_reactor(client).wait
end
|