class CopyTunerClient::Poller

server using the given {Cache} after a set delay.
Starts a background thread that continually resynchronizes with the remote

def delay

def delay
  sleep(polling_delay)
end

def initialize(cache, options)

Options Hash: (**options)
  • :polling_delay (Fixnum) -- how long to wait in between requests
  • :logger (Logger) -- where errors should be logged

Parameters:
  • options (Hash) --
def initialize(cache, options)
  @cache         = cache
  @polling_delay = options[:polling_delay]
  @logger        = options[:logger]
  @stop          = false
end

def poll

def poll
  until @stop
    cache.sync
    logger.flush if logger.respond_to?(:flush)
    delay
  end
rescue InvalidApiKey => error
  logger.error(error.message)
end

def start

def start
  Thread.new { poll } or logger.error("Couldn't start poller thread")
end

def stop

def stop
  @stop = true
end