Sha256: 3f6a63fa2b23b1ac88a56bd9800e00932e57ac33f740f74d7876b91961851853

Contents?: true

Size: 562 Bytes

Versions: 1

Compression:

Stored size: 562 Bytes

Contents

require "eventmachine"
require "em-scheduled-timer/version"

module EventMachine
  class ScheduledTimer
    def initialize(time, callback = nil, &block)
      @signature = EventMachine.add_timer(interval(time), callback || block)
    end

    def cancel
      EventMachine.cancel_timer(@signature)
    end

    private

    def interval(time)
      time.to_time - Time.now
    end
  end

  def self.add_scheduled_timer(*args, &block)
    interval = args.shift
    callback = args.shift || block
    EventMachine::ScheduledTimer.new(interval, callback)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
em-scheduled-timer-0.1.0 lib/em-scheduled-timer.rb