Sha256: aa68ed84c18310db481bc6bfca8a2cba69a311b0578bc5936c679953e31f0785

Contents?: true

Size: 1008 Bytes

Versions: 15

Compression:

Stored size: 1008 Bytes

Contents

# frozen_string_literal: true

module Listen
  module Adapter
    # Polling Adapter that works cross-platform and
    # has no dependencies. This is the adapter that
    # uses the most CPU processing power and has higher
    # file IO than the other implementations.
    #
    class Polling < Base
      OS_REGEXP = // # match every OS

      DEFAULTS = { latency: 1.0, wait_for_delay: 0.05 }.freeze

      private

      def _configure(_, &callback)
        @polling_callbacks ||= []
        @polling_callbacks << callback
      end

      def _run
        loop do
          start = Time.now.to_f
          @polling_callbacks.each do |callback|
            callback.call(nil)
            nap_time = options.latency - (Time.now.to_f - start)
            # TODO: warn if nap_time is negative (polling too slow)
            sleep(nap_time) if nap_time > 0
          end
        end
      end

      def _process_event(dir, _)
        _queue_change(:dir, dir, '.', recursive: true)
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
qiita_org-0.1.35 gems/ruby/2.7.0/gems/listen-3.3.1/lib/listen/adapter/polling.rb
qiita_org-0.1.34 gems/ruby/2.7.0/gems/listen-3.3.1/lib/listen/adapter/polling.rb
qiita_org-0.1.33 gems/ruby/2.7.0/gems/listen-3.3.1/lib/listen/adapter/polling.rb
qiita_org-0.1.32 gems/ruby/2.7.0/gems/listen-3.3.1/lib/listen/adapter/polling.rb
qiita_org-0.1.31 gems/ruby/2.7.0/gems/listen-3.3.1/lib/listen/adapter/polling.rb
qiita_org-0.1.30 gems/ruby/2.7.0/gems/listen-3.3.1/lib/listen/adapter/polling.rb
qiita_org-0.1.29 gems/ruby/2.7.0/gems/listen-3.3.1/lib/listen/adapter/polling.rb
qiita_org-0.1.28 gems/ruby/2.7.0/gems/listen-3.3.1/lib/listen/adapter/polling.rb
qiita_org-0.1.27 gems/ruby/2.7.0/gems/listen-3.3.1/lib/listen/adapter/polling.rb
qiita_org-0.1.26 gems/ruby/2.7.0/gems/listen-3.3.1/lib/listen/adapter/polling.rb
qiita_org-0.1.25 gems/ruby/2.7.0/gems/listen-3.3.1/lib/listen/adapter/polling.rb
listen-3.3.1 lib/listen/adapter/polling.rb
listen-3.3.0 lib/listen/adapter/polling.rb
listen-3.3.0.pre.3 lib/listen/adapter/polling.rb
listen-3.3.0.pre.2 lib/listen/adapter/polling.rb