Sha256: bd5255d1f5d39cf28e117801cec57366eefd2767ec0554617ba3ef26617e4a55
Contents?: true
Size: 671 Bytes
Versions: 8
Compression:
Stored size: 671 Bytes
Contents
module BubbleWrap module Reactor # Creates a one-time timer. class Timer include Eventable # Create a new timer that fires after a given number of seconds 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 # Cancel the timer def cancel @timer.cancel! if @timer trigger(:cancelled) true end end end end
Version data entries
8 entries across 8 versions & 1 rubygems