Class: ThreadTimer
- Inherits:
-
Object
- Object
- ThreadTimer
- Defined in:
- lib/tdl/thread_timer.rb
Instance Method Summary collapse
-
#initialize(timeout_millis, callback) ⇒ ThreadTimer
constructor
A new instance of ThreadTimer.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(timeout_millis, callback) ⇒ ThreadTimer
Returns a new instance of ThreadTimer.
2 3 4 5 6 7 |
# File 'lib/tdl/thread_timer.rb', line 2 def initialize(timeout_millis, callback) @timeout_millis=timeout_millis @continue = true @callback = callback @timer_thread = nil end |
Instance Method Details
#start ⇒ Object
9 10 11 12 |
# File 'lib/tdl/thread_timer.rb', line 9 def start @continue = true @timer_thread = Thread.new { start_timeout } end |
#stop ⇒ Object
14 15 16 17 18 |
# File 'lib/tdl/thread_timer.rb', line 14 def stop @timer_thread.terminate unless @timer_thread.nil? @timer_thread = nil @continue = false end |