Sha256: 1b39f69fc73c3eefb17b47947e7a3c2e27774160a1d132191d328a71f3e9bb73

Contents?: true

Size: 1005 Bytes

Versions: 15

Compression:

Stored size: 1005 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
        Thread.new { _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

15 entries across 15 versions & 1 rubygems

Version Path
listen-2.7.4 lib/listen/adapter/polling.rb
listen-2.7.3 lib/listen/adapter/polling.rb
listen-2.7.2 lib/listen/adapter/polling.rb
listen-2.7.1 lib/listen/adapter/polling.rb
listen-2.7.0 lib/listen/adapter/polling.rb
listen-2.6.2 lib/listen/adapter/polling.rb
listen-2.6.1 lib/listen/adapter/polling.rb
listen-2.6.0 lib/listen/adapter/polling.rb
listen-2.5.0 lib/listen/adapter/polling.rb
listen-2.4.1 lib/listen/adapter/polling.rb
listen-2.4.0 lib/listen/adapter/polling.rb
listen-2.3.1 lib/listen/adapter/polling.rb
listen-2.2.0 lib/listen/adapter/polling.rb
listen-2.1.2 lib/listen/adapter/polling.rb
listen-2.1.1 lib/listen/adapter/polling.rb