Class: Rack::NackMode::Timer::ThreadTimer

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/nack_mode.rb

Instance Method Summary collapse

Constructor Details

#initialize(timeout) ⇒ ThreadTimer

Returns a new instance of ThreadTimer.



181
182
183
184
185
186
187
188
189
# File 'lib/rack/nack_mode.rb', line 181

def initialize(timeout)
  @thread = Thread.new do
    waited = sleep(timeout)
    # if we woke up early, waited < timeout
    if waited >= timeout
      yield
    end
  end
end

Instance Method Details

#cancelObject



191
192
193
# File 'lib/rack/nack_mode.rb', line 191

def cancel
  @thread.run # will wake up early from sleep
end