Class: Restify::Adapter::Typhoeus
- Includes:
- Logging
- Defined in:
- lib/restify/adapter/typhoeus.rb
Constant Summary collapse
- DEFAULT_HEADERS =
{ 'Expect' => '', 'Transfer-Encoding' => '' }.freeze
Instance Attribute Summary collapse
-
#sync ⇒ Object
readonly
Returns the value of attribute sync.
Instance Method Summary collapse
- #call_native(request, writer) ⇒ Object
-
#initialize(sync: false, **options) ⇒ Typhoeus
constructor
A new instance of Typhoeus.
- #sync? ⇒ Boolean
Methods included from Logging
Methods inherited from Base
Constructor Details
#initialize(sync: false, **options) ⇒ Typhoeus
Returns a new instance of Typhoeus.
19 20 21 22 23 24 |
# File 'lib/restify/adapter/typhoeus.rb', line 19 def initialize(sync: false, **) @sync = sync @hydra = ::Typhoeus::Hydra.new(**) @mutex = Mutex.new @signal = ConditionVariable.new end |
Instance Attribute Details
#sync ⇒ Object (readonly)
Returns the value of attribute sync.
12 13 14 |
# File 'lib/restify/adapter/typhoeus.rb', line 12 def sync @sync end |
Instance Method Details
#call_native(request, writer) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/restify/adapter/typhoeus.rb', line 30 def call_native(request, writer) req = convert(request, writer) if sync? req.run else @mutex.synchronize do logger.debug { "[#{self.object_id}/#{Thread.current.object_id}] [#{request.object_id}] request:add method=#{request.method.upcase} url=#{request.uri}" } @hydra.queue(req) @hydra.dequeue_many thread.run unless thread.status end logger.debug { "[#{self.object_id}/#{Thread.current.object_id}] [#{request.object_id}] request:signal" } @signal.signal end end |
#sync? ⇒ Boolean
26 27 28 |
# File 'lib/restify/adapter/typhoeus.rb', line 26 def sync? @sync end |