Sha256: a0961bfadccee569a9f4a65b3579baab252780fa7a474e1d70571701f63dc9e1

Contents?: true

Size: 600 Bytes

Versions: 5

Compression:

Stored size: 600 Bytes

Contents

require 'timers'

class RestCore::Timer
  TimerGen = if Timers.respond_to?(:new)
               Timers.new
             else
               Timers::Group.new
             end

  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

5 entries across 5 versions & 1 rubygems

Version Path
rest-core-3.3.3 lib/rest-core/timer.rb
rest-core-3.3.2 lib/rest-core/timer.rb
rest-core-3.3.1 lib/rest-core/timer.rb
rest-core-3.3.0 lib/rest-core/timer.rb
rest-core-3.2.0 lib/rest-core/timer.rb