Class: Pubnub::Heart

Inherits:
Object show all
Includes:
Celluloid
Defined in:
lib/pubnub/heart.rb

Overview

Heart takes responsibility of heartbeat event

Instance Method Summary (collapse)

Constructor Details

- (Heart) initialize(options)

Returns a new instance of Heart



7
8
9
10
11
# File 'lib/pubnub/heart.rb', line 7

def initialize(options)
  @heartbeat = options[:heartbeat]
  @channel   = options[:channel]
  @app       = options[:app]
end

Instance Method Details

- (Object) beat



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

def beat
  @app.heartbeat(
      channel:   @channel,
      heartbeat: @heartbeat,
      http_sync: true
  )
end

- (Object) start_beating



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pubnub/heart.rb', line 13

def start_beating
  beating = Timers::Group.new

  beat

  beating.every(@heartbeat) do
    Pubnub.logger.debug('Pubnub') { 'Heartbeat!' }
    beat
  end

  loop { beating.wait }
end