Class: Caldecott::TcpConnection

Inherits:
EventMachine::Connection
  • Object
show all
Defined in:
lib/caldecott/tcp_connection.rb

Overview

wrapper to avoid callback and state passing spaghetti

Instance Method Summary collapse

Instance Method Details

#onclose(&blk) ⇒ Object



19
20
21
# File 'lib/caldecott/tcp_connection.rb', line 19

def onclose(&blk)
  @onclose = blk
end

#onopen(&blk) ⇒ Object

callbacks



11
12
13
# File 'lib/caldecott/tcp_connection.rb', line 11

def onopen(&blk)
  @initialized ? blk.call : @onopen = blk
end

#onreceive(&blk) ⇒ Object



15
16
17
# File 'lib/caldecott/tcp_connection.rb', line 15

def onreceive(&blk)
  @onreceive = blk
end

#post_initObject

handle EventMachine::Connection methods



24
25
26
27
# File 'lib/caldecott/tcp_connection.rb', line 24

def post_init
  @initialized = true
  @onopen.call if @onopen
end

#receive_data(data) ⇒ Object



29
30
31
# File 'lib/caldecott/tcp_connection.rb', line 29

def receive_data(data)
  @onreceive.call(data) if @onreceive
end

#unbindObject



33
34
35
# File 'lib/caldecott/tcp_connection.rb', line 33

def unbind
  @onclose.call if @onclose
end