Sha256: 48a018633b7eb1e88842dca196cee1d0a87ed5eb44830cb0402f8a30a157997f

Contents?: true

Size: 830 Bytes

Versions: 62

Compression:

Stored size: 830 Bytes

Contents

module KQueue
  class Watcher
    # The {Watcher} subclass for events fired based on a timer.
    # Timer events are watched via {Queue#watch_timer}.
    class Timer < Watcher
      # The interval on which the timer fires an event, in seconds.
      #
      # @return [Numeric]
      attr_reader :time

      # Creates a new timer Watcher.
      #
      # @private
      def initialize(time, callback)
        time, unit =
          if time < 10**-3
            [(time * 10**9).round, :nseconds]
          elsif time < 1
            [(time * 10**6).round, :useconds]
          elsif time < 10**3 && !time.is_a?(Fixnum)
            [(time * 10**3).round, nil] # milliseconds
          else
            [time.round, :seconds]
          end

        super(queue, time, :timer, Array(unit), nil, callback)
      end
    end
  end
end

Version data entries

62 entries across 54 versions & 8 rubygems

Version Path
rb-kqueue-0.2.8 lib/rb-kqueue/watcher/timer.rb
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/rb-kqueue-0.2.7/lib/rb-kqueue/watcher/timer.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/rb-kqueue-0.2.7/lib/rb-kqueue/watcher/timer.rb
rb-kqueue-0.2.7 lib/rb-kqueue/watcher/timer.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/rb-kqueue-0.2.5/lib/rb-kqueue/watcher/timer.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/rb-kqueue-0.2.6/lib/rb-kqueue/watcher/timer.rb
rb-kqueue-0.2.6 lib/rb-kqueue/watcher/timer.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/rb-kqueue-0.2.5/lib/rb-kqueue/watcher/timer.rb
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/rb-kqueue-0.2.5/lib/rb-kqueue/watcher/timer.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/rb-kqueue-0.2.5/lib/rb-kqueue/watcher/timer.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/rb-kqueue-0.2.5/lib/rb-kqueue/watcher/timer.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rb-kqueue-0.2.5/lib/rb-kqueue/watcher/timer.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/rb-kqueue-0.2.5/lib/rb-kqueue/watcher/timer.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/rb-kqueue-0.2.5/lib/rb-kqueue/watcher/timer.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/rb-kqueue-0.2.5/lib/rb-kqueue/watcher/timer.rb
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/rb-kqueue-0.2.5/lib/rb-kqueue/watcher/timer.rb
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/rb-kqueue-0.2.5/lib/rb-kqueue/watcher/timer.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/rb-kqueue-0.2.5/lib/rb-kqueue/watcher/timer.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/rb-kqueue-0.2.5/lib/rb-kqueue/watcher/timer.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/rb-kqueue-0.2.5/lib/rb-kqueue/watcher/timer.rb