layout | title | permalink | hide | top_name | top_link |
---|---|---|---|---|---|
documentation |
EM-HTTP Adapter |
/adapters/em-http |
true |
Adapters |
./ |
This Adapter uses EventMachine and the tie in em-http-request
It can be used to make parallel requests using EventMachine.
The major difference between this and EMSynchrony is that it does not use fibers.
Error handling and responses have a slightly different behaviour and structure in some cases. Please run thorough testing scenarios, including connection failures and SSL failures
You will need to add em-http-request to your Gemfile:
# Gemfile
gem 'em-http-request'
require 'faraday'
require 'em-http-request'
conn = Faraday.new(...) do |f|
# no custom options available
f.adapter :em_http
end
require 'faraday'
require 'em-http-request'
urls = Array.new(5) { 'http://127.0.0.1:3000' }
conn = Faraday::Connection.new do |builder|
builder.adapter :em_http
end
begin
conn.in_parallel do
puts "Parallel manager: #{conn.parallel_manager}"
@responses = urls.map do |url|
conn.get(url)
end
end
end
# Gather responses outside of block
puts @responses.map(&:status).join(', ')
puts @responses.map(&:status).compact.count