Class: Faraday::Adapter::EMSynchrony::ParallelManager

Inherits:
Object
  • Object
show all
Defined in:
lib/faraday/adapter/em_synchrony/parallel_manager.rb

Overview

A parallel manager for EMSynchrony.

Instance Method Summary collapse

Instance Method Details

#add(request, method, *args, &block) ⇒ Object

Add requests to queue.

Parameters:

  • request (EM::HttpRequest)
  • method (Symbol, String)

    HTTP method

  • args (Array)

    the rest of the positional arguments



13
14
15
16
17
18
19
20
# File 'lib/faraday/adapter/em_synchrony/parallel_manager.rb', line 13

def add(request, method, *args, &block)
  queue << {
    request: request,
    method: method,
    args: args,
    block: block
  }
end

#runObject

Run all requests on queue with ‘EM::Synchrony::Multi`, wrapping it in a reactor and fiber if needed.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/faraday/adapter/em_synchrony/parallel_manager.rb', line 24

def run
  result = nil
  if !EM.reactor_running?
    EM.run do
      Fiber.new do
        result = perform
        EM.stop
      end.resume
    end
  else
    result = perform
  end
  result
end