Class: Slack::RealTime::Concurrency::Async::Socket

Inherits:
Socket
  • Object
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, #start_sync, #time_since_last_message

Constructor Details

This class inherits a constructor from Slack::RealTime::Socket

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



18
19
20
# File 'lib/slack/real_time/concurrency/async.rb', line 18

def client
  @client
end

Instance Method Details

#closeObject



60
61
62
63
64
# File 'lib/slack/real_time/concurrency/async.rb', line 60

def close
  @closing = true
  @driver.close if @driver
  super
end

#connect!Object



55
56
57
58
# File 'lib/slack/real_time/concurrency/async.rb', line 55

def connect!
  super
  run_loop
end

#current_timeObject



51
52
53
# File 'lib/slack/real_time/concurrency/async.rb', line 51

def current_time
  ::Async::Clock.now
end

#disconnect!Object



46
47
48
49
# File 'lib/slack/real_time/concurrency/async.rb', line 46

def disconnect!
  super
  @reactor.cancel
end

#restart_async(client, new_url) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/slack/real_time/concurrency/async.rb', line 36

def restart_async(client, new_url)
  @url = new_url
  @last_message_at = current_time
  return unless @reactor

  @reactor.async do
    client.run_loop
  end
end

#run_loopObject



66
67
68
69
70
71
# File 'lib/slack/real_time/concurrency/async.rb', line 66

def run_loop
  @closing = false
  while @driver && @driver.next_event
    # $stderr.puts event.inspect
  end
end

#start_async(client) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/slack/real_time/concurrency/async.rb', line 20

def start_async(client)
  @reactor = Reactor.new
  Thread.new do
    if client.run_ping?
      @reactor.every(client.websocket_ping) do
        client.run_ping!
      end
    end
    @reactor.run do |task|
      task.async do
        client.run_loop
      end
    end
  end
end