Sha256: d2cfff94d3cc47f51c3037b088c13ab29364738da276fb064f29583e7988ca8e

Contents?: true

Size: 467 Bytes

Versions: 6

Compression:

Stored size: 467 Bytes

Contents

module ZMachine
  class Timer

    attr_accessor :interval

    def initialize(interval, callback=nil, &block)
      @interval = interval
      @callback = callback || block
      schedule
    end

    def schedule
      @timer = ZMachine.add_timer(@interval, method(:fire))
    end

    def fire
      @callback.call
    end

    def cancel
      @timer.cancel
    end
  end

  class PeriodicTimer < Timer

    def fire
      super
      schedule
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
zmachine-0.4.3 lib/zmachine/timers.rb
zmachine-0.4.2 lib/zmachine/timers.rb
zmachine-0.4.1 lib/zmachine/timers.rb
zmachine-0.4.0 lib/zmachine/timers.rb
zmachine-0.3.2 lib/zmachine/timers.rb
zmachine-0.3.0 lib/zmachine/timers.rb