Sha256: f702e644a09b1f2d2c16f02a9664982d7b7c35153917da07e1ded3670b69a10f

Contents?: true

Size: 652 Bytes

Versions: 5

Compression:

Stored size: 652 Bytes

Contents

module Ludy
  # whenever a Timer was timeout, it was thrown
  class Timeout < Exception; end
  # simple and stupid timer for puzzle_generator...
  class Timer
    # create a timer for timeout seconds.
    def initialize timeout
      @timeout = timeout
    end
    # start ticking
    def start
      @now = Time.now
      @parent = Thread.current
      @thread = Thread.new{
        sleep @timeout
        @parent.raise Timeout.new("timeout for #{@timeout} seconds.")
      }
      self
    end
    # total time until start ticking
    def total_time
      Time.now - @now
    end
    # stop ticking
    def stop
      @thread.kill
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
godfat-ludy-0.1.13 lib/ludy/timer.rb
ludy-0.1.15 lib/ludy/timer.rb
ludy-0.1.13 lib/ludy/timer.rb
ludy-0.1.10 lib/ludy/timer.rb
ludy-0.1.11 lib/ludy/timer.rb