Sha256: aadccb5dbda09f217cd4fdf49f26fe5edf9ca7781c9f930c9170d8efb205a153

Contents?: true

Size: 615 Bytes

Versions: 8

Compression:

Stored size: 615 Bytes

Contents

class RestCore::Timeout::TimerThread
  attr_accessor :timeout, :error

  def initialize timeout, error, &block
    t = Thread.current
    self.timeout = timeout
    self.error   = error
    self.block   = block || lambda{ t.raise error }
    @canceled    = false
    start
  end

  def on_timeout &block
    self.block = block
  end

  def cancel
    @canceled = true
  end

  def canceled?
    @canceled
  end

  def start
    return if timeout.nil? || timeout.zero?
    self.thread = Thread.new{
      sleep(timeout)
      block.call unless canceled?
    }
  end

  protected
  attr_accessor :block, :thread
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rest-core-2.1.2 lib/rest-core/middleware/timeout/timer_thread.rb
rest-core-2.1.1 lib/rest-core/middleware/timeout/timer_thread.rb
rest-core-2.1.0 lib/rest-core/middleware/timeout/timer_thread.rb
rest-core-2.0.4 lib/rest-core/middleware/timeout/timer_thread.rb
rest-core-2.0.3 lib/rest-core/middleware/timeout/timer_thread.rb
rest-core-2.0.2 lib/rest-core/middleware/timeout/timer_thread.rb
rest-core-2.0.1 lib/rest-core/middleware/timeout/timer_thread.rb
rest-core-2.0.0 lib/rest-core/middleware/timeout/timer_thread.rb