1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/lib/action_cable/connection/heartbeat.rb
2015-06-21 22:49:29 +02:00

27 lines
No EOL
546 B
Ruby

module ActionCable
module Connection
class Heartbeat
BEAT_INTERVAL = 3
def initialize(connection)
@connection = connection
end
def start
beat
@timer = EventMachine.add_periodic_timer(BEAT_INTERVAL) { beat }
end
def stop
EventMachine.cancel_timer(@timer) if @timer
end
private
attr_reader :connection
def beat
connection.transmit({ identifier: '_ping', message: Time.now.to_i }.to_json)
end
end
end
end