Class: Restify::Adapter::Typhoeus

Inherits:
Object
  • Object
show all
Defined in:
lib/restify/adapter/typhoeus.rb

Instance Method Summary collapse

Constructor Details

#initializeTyphoeus



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/restify/adapter/typhoeus.rb', line 9

def initialize
  @queue = Queue.new
  @hydra = ::Typhoeus::Hydra.new

  Thread.new do
    begin
      loop do
        while (req = convert(*@queue.pop))
          @hydra.queue req

          if @queue.size == 0
            @hydra.run
          end
        end
      end
    rescue Exception => e
      puts "#{self.class}: #{e.message}"
    end
  end
end

Instance Method Details

#call(request) ⇒ Object



34
35
36
37
38
# File 'lib/restify/adapter/typhoeus.rb', line 34

def call(request)
  Promise.create do |writer|
    queue request, writer
  end
end

#queue(request, writer) ⇒ Object



30
31
32
# File 'lib/restify/adapter/typhoeus.rb', line 30

def queue(request, writer)
  @queue.push [request, writer]
end