Class: Restify::Adapter::Typhoeus
- Inherits:
-
Object
- Object
- Restify::Adapter::Typhoeus
- Defined in:
- lib/restify/adapter/typhoeus.rb
Instance Method Summary collapse
- #call(request) ⇒ Object
-
#initialize(**options) ⇒ Typhoeus
constructor
A new instance of Typhoeus.
- #queue(request, writer) ⇒ Object
- #sync? ⇒ Boolean
Constructor Details
#initialize(**options) ⇒ Typhoeus
Returns a new instance of Typhoeus.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/restify/adapter/typhoeus.rb', line 9 def initialize(**) @queue = Queue.new @hydra = ::Typhoeus::Hydra.new @options = 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.}" end end end |
Instance Method Details
#call(request) ⇒ Object
44 45 46 47 48 |
# File 'lib/restify/adapter/typhoeus.rb', line 44 def call(request) Promise.create do |writer| queue request, writer end end |
#queue(request, writer) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/restify/adapter/typhoeus.rb', line 35 def queue(request, writer) if sync? @hydra.queue convert request, writer @hydra.run else @queue.push [request, writer] end end |
#sync? ⇒ Boolean
31 32 33 |
# File 'lib/restify/adapter/typhoeus.rb', line 31 def sync? @options.fetch :sync, false end |