Sha256: 32c83503224050e6625405d502f63b291ea554b782038fb9fe318ec102678eb0

Contents?: true

Size: 534 Bytes

Versions: 7

Compression:

Stored size: 534 Bytes

Contents

module Larynx
  # Adds restart to EM timer class. Implementation influenced by EM::PeriodicTimer class
  # so hopefully it should not cause any issues.
  class RestartableTimer < EM::Timer
    def initialize(interval, callback=nil, &block)
      @interval = interval
      @code = callback || block
      schedule
    end

    # Restart the timer
    def restart
      cancel
      schedule
    end

    def schedule
      @signature = EM::add_timer(@interval, method(:fire))
    end

    def fire
      @code.call
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
larynx-0.1.6 lib/larynx/restartable_timer.rb
larynx-0.1.5 lib/larynx/restartable_timer.rb
larynx-0.1.4 lib/larynx/restartable_timer.rb
larynx-0.1.3 lib/larynx/restartable_timer.rb
larynx-0.1.2 lib/larynx/restartable_timer.rb
larynx-0.1.1 lib/larynx/restartable_timer.rb
larynx-0.1.0 lib/larynx/restartable_timer.rb