Sha256: e8730c509731cf56efe5abe028df0d4990e20b49f05cbe5ddc292f6439e90359

Contents?: true

Size: 1.53 KB

Versions: 50

Compression:

Stored size: 1.53 KB

Contents

module Listen
  module Adapters

    # The default delay between checking for changes.
    DEFAULT_POLLING_LATENCY = 1.0

    # 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 that the other implementations.
    #
    class Polling < Adapter
      extend DependencyManager

      # Initialize the Adapter. See {Listen::Adapter#initialize} for more info.
      #
      def initialize(directories, options = {}, &callback)
        @latency ||= DEFAULT_POLLING_LATENCY
        super
      end

      # Start the adapter.
      #
      # @param [Boolean] blocking whether or not to block the current thread after starting
      #
      def start(blocking = true)
        @mutex.synchronize do
          return if @stop == false
          super
        end

        @poll_thread = Thread.new { poll }
        @poll_thread.join if blocking
      end

      # Stop the adapter.
      #
      def stop
        @mutex.synchronize do
          return if @stop == true
          super
        end

        @poll_thread.join
      end

    private

      # Poll listener directory for file system changes.
      #
      def poll
        until @stop
          next if @paused

          start = Time.now.to_f
          @callback.call(@directories.dup, :recursive => true)
          @turnstile.signal
          nap_time = @latency - (Time.now.to_f - start)
          sleep(nap_time) if nap_time > 0
        end
      rescue Interrupt
      end

    end

  end
end

Version data entries

50 entries across 45 versions & 7 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/sass-3.2.19/vendor/listen/lib/listen/adapters/polling.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/sass-3.2.19/vendor/listen/lib/listen/adapters/polling.rb
sadui-0.0.4 vendor/bundle/ruby/2.1.0/gems/sass-3.2.14/vendor/listen/lib/listen/adapters/polling.rb
sadui-0.0.4 vendor/bundle/ruby/2.0.0/gems/sass-3.2.14/vendor/listen/lib/listen/adapters/polling.rb
sass-3.2.19 vendor/listen/lib/listen/adapters/polling.rb
sass-3.2.18 vendor/listen/lib/listen/adapters/polling.rb
sass-3.2.17 vendor/listen/lib/listen/adapters/polling.rb
sass-3.2.16 vendor/listen/lib/listen/adapters/polling.rb
sass-3.3.0 vendor/listen/lib/listen/adapters/polling.rb
sass-3.2.15 vendor/listen/lib/listen/adapters/polling.rb
sass-3.3.0.rc.3 vendor/listen/lib/listen/adapters/polling.rb
sass-3.2.14 vendor/listen/lib/listen/adapters/polling.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/sass-3.2.13/vendor/listen/lib/listen/adapters/polling.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/sass-3.2.12/vendor/listen/lib/listen/adapters/polling.rb
sass-3.2.13 vendor/listen/lib/listen/adapters/polling.rb
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/sass-3.2.12/vendor/listen/lib/listen/adapters/polling.rb
sass-3.3.0.rc.2 vendor/listen/lib/listen/adapters/polling.rb
sass-3.2.12 vendor/listen/lib/listen/adapters/polling.rb
sass-3.2.11 vendor/listen/lib/listen/adapters/polling.rb
sass-3.2.10 vendor/listen/lib/listen/adapters/polling.rb