class RubyGo::Timeout

Attributes

timeout_at[R]

Public Class Methods

new(seconds) click to toggle source
# File lib/ruby_go/timeout.rb, line 4
def initialize(seconds)
  @mutex = Mutex.new
  @timeout = false
  @timeout_at = Time.now() + seconds
end

Public Instance Methods

pop(non_block = true) click to toggle source
# File lib/ruby_go/timeout.rb, line 10
def pop(non_block = true)
  return true if @timeout

  @mutex.synchronize do
    diff = @timeout_at - Time.now()
    @timeout = true if diff <= 0
  end

  if @timeout
    true
  else
    raise ThreadError
  end
end