Module: Typhoeus::Request::Callbacks
- Included in:
- Typhoeus::Request
- Defined in:
- lib/typhoeus/request/callbacks.rb
Overview
If you’re using the Hydra to execute multiple requests, then callbacks are delaying the request execution.
This module contains the logic for the response callbacks. The on_complete callback is the only one at the moment.
You can set multiple callbacks, which are then executed in the same order.
request.on_complete { |response| p 1 }
request.on_complete { |response| p 2 }
request.execute_callbacks
#=> 1
#=> 2
You can clear the callbacks:
request.on_complete { |response| p 1 }
request.on_complete { |response| p 2 }
request.on_complete.clear
request.execute_callbacks
#=> []
Defined Under Namespace
Modules: Types
Instance Method Summary collapse
-
#execute_callbacks ⇒ void
private
Execute necessary callback and yields response.
-
#execute_headers_callbacks(response) ⇒ Array<Object>
private
Execute the headers callbacks and yields response.
Instance Method Details
#execute_callbacks ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Execute necessary callback and yields response. This include in every case on_complete, on_success if successful and on_failure if not.
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/typhoeus/request/callbacks.rb', line 119 def execute_callbacks callbacks = Typhoeus.on_complete + on_complete if response && response.success? callbacks += Typhoeus.on_success + on_success elsif response callbacks += Typhoeus.on_failure + on_failure end callbacks.map do |callback| self.response.handled_response = callback.call(self.response) end end |
#execute_headers_callbacks(response) ⇒ Array<Object>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Execute the headers callbacks and yields response.
103 104 105 106 107 |
# File 'lib/typhoeus/request/callbacks.rb', line 103 def execute_headers_callbacks(response) (Typhoeus.on_headers + on_headers).map do |callback| callback.call(response) end end |