Class: Faraday::Adapter::EMHttp::Manager
- Defined in:
- lib/faraday/adapter/em_http.rb
Overview
The parallel manager is designed to start an EventMachine loop and block until all registered requests have been completed.
Instance Method Summary collapse
- #add ⇒ Object
- #check_finished ⇒ Object
-
#initialize ⇒ Manager
constructor
A new instance of Manager.
- #perform_request ⇒ Object
- #reset ⇒ Object
- #run ⇒ Object
- #running? ⇒ Boolean
Constructor Details
#initialize ⇒ Manager
Returns a new instance of Manager.
150 151 152 |
# File 'lib/faraday/adapter/em_http.rb', line 150 def initialize reset end |
Instance Method Details
#add ⇒ Object
164 165 166 167 168 169 170 171 |
# File 'lib/faraday/adapter/em_http.rb', line 164 def add if running? perform_request { yield } else @registered_procs << Proc.new end @num_registered += 1 end |
#check_finished ⇒ Object
195 196 197 198 199 |
# File 'lib/faraday/adapter/em_http.rb', line 195 def check_finished if @num_succeeded + @errors.size == @num_registered EventMachine.stop end end |
#perform_request ⇒ Object
189 190 191 192 193 |
# File 'lib/faraday/adapter/em_http.rb', line 189 def perform_request client = yield client.callback { @num_succeeded += 1; check_finished } client.errback { @errors << client.error; check_finished } end |
#reset ⇒ Object
154 155 156 157 158 159 160 |
# File 'lib/faraday/adapter/em_http.rb', line 154 def reset @registered_procs = [] @num_registered = 0 @num_succeeded = 0 @errors = [] @running = false end |
#run ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/faraday/adapter/em_http.rb', line 173 def run if @num_registered > 0 @running = true EventMachine.run do @registered_procs.each do |proc| perform_request(&proc) end end if @errors.size > 0 raise Faraday::Error::ClientError, @errors.first || "connection failed" end end ensure reset end |
#running? ⇒ Boolean
162 |
# File 'lib/faraday/adapter/em_http.rb', line 162 def running?() @running end |