Sha256: b7f63821c3005b105774c5bcac759e6ffc35c34df775fc903f06f9555a1c2127

Contents?: true

Size: 990 Bytes

Versions: 9

Compression:

Stored size: 990 Bytes

Contents

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
      DEFAULT_POLLING_LATENCY = 1.0

      def self.usable?
        true
      end

      def start
        _poll_directories
      end

      private

      def _latency
        listener.options[:latency] || DEFAULT_POLLING_LATENCY
      end

      def _poll_directories
        _napped_loop do
          listener.directories.each do |path|
            _notify_change(path, type: 'Dir', recursive: true)
          end
        end
      end

      def _napped_loop
        loop do
          _nap_time { yield }
        end
      end

      def _nap_time
        start = Time.now.to_f
        yield
        nap_time = _latency - (Time.now.to_f - start)
        sleep(nap_time) if nap_time > 0
      end
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
listen-2.1.0 lib/listen/adapter/polling.rb
listen-2.0.4 lib/listen/adapter/polling.rb
listen-2.0.3 lib/listen/adapter/polling.rb
listen-2.0.2 lib/listen/adapter/polling.rb
listen-2.0.1 lib/listen/adapter/polling.rb
listen-2.0.0 lib/listen/adapter/polling.rb
listen-2.0.0.pre.1 lib/listen/adapter/polling.rb
listen-2.0.0.beta.2 lib/listen/adapter/polling.rb
listen-2.0.0.beta.1 lib/listen/adapter/polling.rb