module Reconnect
Module Reconnect
provides Reconnection Support
@author Piyush Wani <piyushwww13@gmail.com>
Public Instance Methods
initialize_reconnect()
click to toggle source
Initializes Reconnection related entities
# File lib/socketclusterclient/reconnect.rb, line 13 def initialize_reconnect @reconnect_interval = 2000 @max_reconnect_interval = 30_000 @max_attempts = nil # unlimited reconnection attempt @attempts_made = 0 end
set_reconnection_listener(reconnect_interval, max_reconnect_interval, max_attempts = @max_attempts)
click to toggle source
Adds a handler for Reconnection
@param [Integer] reconnect_interval A interval for reconnection attempt( in milliseconds ) @param [Integer] max_reconnect_interval A max Limit for reconnection interval (in milliseconds) @param [Integer] max_attempts A max number of Reconnection Attempts allowed
# File lib/socketclusterclient/reconnect.rb, line 29 def set_reconnection_listener(reconnect_interval, max_reconnect_interval, max_attempts = @max_attempts) @reconnect_interval = reconnect_interval > max_reconnect_interval ? max_reconnect_interval : reconnect_interval @max_reconnect_interval = max_reconnect_interval @max_attempts = max_attempts @attempts_made = 0 end
Private Instance Methods
should_reconnect()
click to toggle source
Check for reconnection to server
@return [Boolean] Allow reconnection
# File lib/socketclusterclient/reconnect.rb, line 44 def should_reconnect @enable_reconnection && (@max_attempts.nil? || (@attempts_made < @max_attempts)) end