Class: Slack::RealTime::Concurrency::Celluloid::Socket

Inherits:
Socket
  • Object
show all
Extended by:
Forwardable
Includes:
Celluloid::IO, Celluloid::Logger
Defined in:
lib/slack/real_time/concurrency/celluloid.rb

Defined Under Namespace

Classes: Actor

Constant Summary collapse

BLOCK_SIZE =
4096

Instance Attribute Summary collapse

Attributes inherited from Socket

#driver, #options, #url

Instance Method Summary collapse

Methods inherited from Socket

#disconnect!, #send_data, #start_sync

Constructor Details

#initialize(*args) ⇒ Socket

Returns a new instance of Socket.



22
23
24
25
# File 'lib/slack/real_time/concurrency/celluloid.rb', line 22

def initialize(*args)
  super
  @driver = build_driver
end

Instance Attribute Details

#socketObject (readonly)

Returns the value of attribute socket.



20
21
22
# File 'lib/slack/real_time/concurrency/celluloid.rb', line 20

def socket
  @socket
end

Instance Method Details

#connect! {|driver| ... } ⇒ Object

Yield Parameters:

  • driver (WebSocket::Driver)


28
29
30
31
32
33
# File 'lib/slack/real_time/concurrency/celluloid.rb', line 28

def connect!
  super

  driver.start
  future.run_loop
end

#readObject



41
42
43
44
# File 'lib/slack/real_time/concurrency/celluloid.rb', line 41

def read
  buffer = socket.readpartial(BLOCK_SIZE)
  driver.parse buffer
end

#run_loopObject



35
36
37
38
39
# File 'lib/slack/real_time/concurrency/celluloid.rb', line 35

def run_loop
  loop { read } if socket
rescue EOFError
  # connection closed
end

#start_asyncObject



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

def start_async
  future = yield self if block_given?

  Actor.new(future)
end