Class: AmfSocket::Heartbeat

Inherits:
Object
  • Object
show all
Defined in:
lib/amf_socket/heartbeat.rb

Constant Summary collapse

INTERVAL =

Seconds.

1

Instance Method Summary collapse

Constructor Details

#initializeHeartbeat

Returns a new instance of Heartbeat.



4
5
6
7
# File 'lib/amf_socket/heartbeat.rb', line 4

def initialize
  @objects = Set.new
  start unless AmfSocket.test_mode?
end

Instance Method Details

#add(object) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/amf_socket/heartbeat.rb', line 26

def add(object)
  return false if @objects.include?(object)

  @objects.add(object)

  return true
end

#remove(object) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/amf_socket/heartbeat.rb', line 34

def remove(object)
  return false unless @objects.include?(object)

  @objects.delete(object)

  return true
end

#startObject



9
10
11
12
13
14
15
# File 'lib/amf_socket/heartbeat.rb', line 9

def start
  return false unless @timer.nil?

  @timer = EM::PeriodicTimer.new(INTERVAL, method(:timer_handler))

  return true
end

#stopObject



17
18
19
20
21
22
23
24
# File 'lib/amf_socket/heartbeat.rb', line 17

def stop
  return false unless @timer

  @timer.cancel
  @timer = nil

  return true
end