Class: Ludy::Timer
- Inherits:
-
Object
- Object
- Ludy::Timer
- Defined in:
- lib/ludy/timer.rb
Overview
simple and stupid timer for puzzle_generator…
Instance Method Summary collapse
-
#initialize(timeout) ⇒ Timer
constructor
create a timer for timeout seconds.
-
#start ⇒ Object
start ticking.
-
#stop ⇒ Object
stop ticking.
-
#total_time ⇒ Object
total time until start ticking.
Constructor Details
#initialize(timeout) ⇒ Timer
create a timer for timeout seconds.
8 9 10 |
# File 'lib/ludy/timer.rb', line 8 def initialize timeout @timeout = timeout end |
Instance Method Details
#start ⇒ Object
start ticking
12 13 14 15 16 17 18 19 20 |
# File 'lib/ludy/timer.rb', line 12 def start @now = Time.now @parent = Thread.current @thread = Thread.new{ sleep @timeout @parent.raise Timeout.new("timeout for #{@timeout} seconds.") } self end |
#stop ⇒ Object
stop ticking
26 27 28 |
# File 'lib/ludy/timer.rb', line 26 def stop @thread.kill end |
#total_time ⇒ Object
total time until start ticking
22 23 24 |
# File 'lib/ludy/timer.rb', line 22 def total_time Time.now - @now end |