mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
27 lines
No EOL
546 B
Ruby
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 |