Class: ThreadTimer

Inherits:
Object
  • Object
show all
Defined in:
lib/tdl/thread_timer.rb

Instance Method Summary collapse

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

#startObject



9
10
11
12
# File 'lib/tdl/thread_timer.rb', line 9

def start
  @continue = true
  @timer_thread = Thread.new { start_timeout }
end

#stopObject



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