class SitePrism::Timer
SitePrism::Timer
-
Used to count asynchronously towards an overall desired duration or condition (Block)
Attributes
wait_time[R]
Public Class Methods
new(wait_time)
click to toggle source
# File lib/site_prism/timer.rb, line 17 def initialize(wait_time) @wait_time = wait_time @done = false end
run(wait_time, &block)
click to toggle source
Return &block
Count towards a specified time (Supplied)
# File lib/site_prism/timer.rb, line 13 def self.run(wait_time, &block) new(wait_time).run(&block) end
Public Instance Methods
done?()
click to toggle source
Return Boolean
Whether the timer has completed
# File lib/site_prism/timer.rb, line 25 def done? @done == true end
run() { |self| ... }
click to toggle source
Return &block
Start the Timer
and re-evaluate the block repeatedly
# File lib/site_prism/timer.rb, line 32 def run start yield self ensure stop end
start()
click to toggle source
Return [Boolean, Nil]
Start the Timer
in a separate process
# File lib/site_prism/timer.rb, line 42 def start stop return if wait_time.zero? @done = false @thread = Thread.start do sleep wait_time @done = true end end
stop()
click to toggle source
Return True
Forcibly stop the timer, and kill any threads created by it
# File lib/site_prism/timer.rb, line 56 def stop if @thread @thread.kill @thread.join @thread = nil end @done = true end