Sha256: 40c568a8269073492c6bc4c5abc7fb4c1fd7a25fa04ae6fda09388e1c9af4c66

Contents?: true

Size: 657 Bytes

Versions: 6

Compression:

Stored size: 657 Bytes

Contents

module BubbleWrap
  module Reactor
    # Creates a repeating timer.
    class PeriodicTimer
      include Eventable

      attr_accessor :interval

      # Create a new timer that fires after a given number of seconds
      def initialize(interval, callback=nil, &blk)
        self.interval = interval
        fire = proc {
          (callback || blk).call
          trigger(:fired)
        }
        @timer = NSTimer.scheduledTimerWithTimeInterval(interval,target: fire, selector: 'call:', userInfo: nil, repeats: true)
      end

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

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bubble-wrap-1.1.5 motion/reactor/periodic_timer.rb
bubble-wrap-1.1.4 motion/reactor/periodic_timer.rb
bubble-wrap-1.1.3 motion/reactor/periodic_timer.rb
bubble-wrap-1.1.2 motion/reactor/periodic_timer.rb
bubble-wrap-1.1.1 motion/reactor/periodic_timer.rb
bubble-wrap-1.1.0 motion/reactor/periodic_timer.rb