Sha256: 37fe90b7c94d5b295f75fa099651c83cdd188620d11b464161075b4e93d03de2

Contents?: true

Size: 489 Bytes

Versions: 3

Compression:

Stored size: 489 Bytes

Contents

require 'timers'

class RestCore::Timer
  TimerGen = Timers.new

  attr_accessor :timeout, :error
  def initialize timeout, error, &block
    self.timeout = timeout
    self.error   = error
    self.block   = block
    start
  end

  def on_timeout &block
    self.block = block
  end

  def cancel
    timer.cancel
  end

  def start
    return if timeout.nil? || timeout.zero?
    self.timer = TimerGen.after(timeout){ block.call }
  end

  protected
  attr_accessor :block, :timer
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rest-core-3.1.1 lib/rest-core/timer.rb
rest-core-3.1.0 lib/rest-core/timer.rb
rest-core-3.0.0 lib/rest-core/timer.rb