Sha256: 9e1344159146a9e5170e8a32cdf20de12354d3f809d0920141ecd0ab89001981

Contents?: true

Size: 1.58 KB

Versions: 109

Compression:

Stored size: 1.58 KB

Contents

module Faraday
  class Adapter
    class EMSynchrony < Faraday::Adapter
      class ParallelManager

        # Add requests to queue. The `request` argument should be a
        # `EM::HttpRequest` object.
        def add(request, method, *args, &block)
          queue << {
            :request => request,
            :method => method,
            :args => args,
            :block => block
          }
        end

        # Run all requests on queue with `EM::Synchrony::Multi`, wrapping
        # it in a reactor and fiber if needed.
        def run
          result = nil
          if !EM.reactor_running?
            EM.run {
              Fiber.new do
                result = perform
                EM.stop
              end.resume
            }
          else
            result = perform
          end
          result
        end


        private

        # The request queue.
        def queue
          @queue ||= []
        end

        # Main `EM::Synchrony::Multi` performer.
        def perform
          multi = ::EM::Synchrony::Multi.new

          queue.each do |item|
            method = "a#{item[:method]}".to_sym

            req = item[:request].send(method, *item[:args])
            req.callback(&item[:block])

            req_name = "req_#{multi.requests.size}".to_sym
            multi.add(req_name, req)
          end

          # Clear the queue, so parallel manager objects can be reused.
          @queue = []

          # Block fiber until all requests have returned.
          multi.perform
        end

      end # ParallelManager
    end # EMSynchrony
  end # Adapter
end # Faraday

Version data entries

109 entries across 101 versions & 13 rubygems

Version Path
faraday-0.17.6 lib/faraday/adapter/em_synchrony/parallel_manager.rb
faraday-0.17.5 lib/faraday/adapter/em_synchrony/parallel_manager.rb
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_synchrony/parallel_manager.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_synchrony/parallel_manager.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_synchrony/parallel_manager.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_synchrony/parallel_manager.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_synchrony/parallel_manager.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_synchrony/parallel_manager.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_synchrony/parallel_manager.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_synchrony/parallel_manager.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_synchrony/parallel_manager.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_synchrony/parallel_manager.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_synchrony/parallel_manager.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_synchrony/parallel_manager.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_synchrony/parallel_manager.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_synchrony/parallel_manager.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_synchrony/parallel_manager.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_synchrony/parallel_manager.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_synchrony/parallel_manager.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/faraday-0.15.4/lib/faraday/adapter/em_synchrony/parallel_manager.rb