class BubbleWrap::Reactor::Timer
Creates a one-time timer.
Public Class Methods
new(leeway, callback=nil, &blk)
click to toggle source
Create a new timer that fires after a given number of seconds
# File motion/reactor/timer.rb, line 8 def initialize(leeway, callback=nil, &blk) queue = Dispatch::Queue.current @timer = Dispatch::Source.timer(leeway, Dispatch::TIME_FOREVER, 0.0, queue) do |src| begin (callback || blk).call trigger(:fired) ensure src.cancel! end end end
Public Instance Methods
cancel()
click to toggle source
Cancel the timer
# File motion/reactor/timer.rb, line 21 def cancel @timer.cancel! if @timer trigger(:cancelled) true end