Sha256: 336c526f49ca72c4104f4d2f2f13579e2731bec94d2c67f4baa9ab5a8db56d50

Contents?: true

Size: 598 Bytes

Versions: 10

Compression:

Stored size: 598 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(interval, callback=nil, &blk)
        fire = proc {
          (callback || blk).call
          trigger(:fired)
        }
        @timer = NSTimer.scheduledTimerWithTimeInterval(interval,target: fire, selector: 'call:', userInfo: nil, repeats: false)
      end

      # Cancel the timer
      def cancel
        @timer.invalidate
        trigger(:cancelled)
        true
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
bubble-wrap-1.3.0 motion/reactor/timer.rb
bubble-wrap-1.3.0.osx motion/reactor/timer.rb
bubble-wrap-1.2.0 motion/reactor/timer.rb
bubble-wrap-1.2.0.pre motion/reactor/timer.rb
bubble-wrap-1.1.5 motion/reactor/timer.rb
bubble-wrap-1.1.4 motion/reactor/timer.rb
bubble-wrap-1.1.3 motion/reactor/timer.rb
bubble-wrap-1.1.2 motion/reactor/timer.rb
bubble-wrap-1.1.1 motion/reactor/timer.rb
bubble-wrap-1.1.0 motion/reactor/timer.rb