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.
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
#=> nil
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 and on_progress, on_success if successful and on_failure if not.
136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/typhoeus/request/callbacks.rb', line 136 def execute_callbacks callbacks = Typhoeus.on_complete + Typhoeus.on_progress + on_complete + on_progress if response && response.success? callbacks += Typhoeus.on_success + on_success elsif response callbacks += Typhoeus.on_failure + on_failure end callbacks.each 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.
120 121 122 123 124 |
# File 'lib/typhoeus/request/callbacks.rb', line 120 def execute_headers_callbacks(response) (Typhoeus.on_headers + on_headers).map do |callback| callback.call(response) end end |