Class: Rack::NackMode::Timer::ThreadTimer
- Inherits:
-
Object
- Object
- Rack::NackMode::Timer::ThreadTimer
- Defined in:
- lib/rack/nack_mode.rb
Instance Method Summary collapse
- #cancel ⇒ Object
-
#initialize(timeout) ⇒ ThreadTimer
constructor
A new instance of ThreadTimer.
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
#cancel ⇒ Object
191 192 193 |
# File 'lib/rack/nack_mode.rb', line 191 def cancel @thread.run # will wake up early from sleep end |