Skip to content

Provides concurrent version of each() which works in EventMachine + Fiber environment.

Notifications You must be signed in to change notification settings

gimite/em-fiber-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Usage example

Fetches 3 URLs cuncurrently using em-synchrony:

require "em-synchrony"
require "em-synchrony/em-http"
require "em-fiber-utils"

EM.synchrony do
  urls = ["http://www.google.com/", "http://www.yahoo.com/", "http://www.bing.com/"]
  EM::FiberUtils.concurrent_each(urls) do |url|
    p EventMachine::HttpRequest.new(url).get.response
  end
  # Reaches here when we have got all responses.
  EM.stop
end

You can do the same thing in Sinatra + rack-fiber_pool:

require "sinatra"
require "em-synchrony"
require "em-synchrony/em-http"
require "rack/fiber_pool"
require "em-fiber-utils"

use(Rack::FiberPool)

get("/") do
  urls = ["http://www.google.com/", "http://www.yahoo.com/", "http://www.bing.com/"]
  EM::FiberUtils.concurrent_each(urls) do |url|
    p EventMachine::HttpRequest.new(url).get.response
  end
  # Reaches here when we have got all responses.
  return "ok"
end

It also provides EM::FiberUtils.concurrent_map:

urls = ["http://www.google.com/", "http://www.yahoo.com/", "http://www.bing.com/"]
reses = EM::FiberUtils.concurrent_map(urls) do |url|
  EventMachine::HttpRequest.new(url).get.response
end

About

Provides concurrent version of each() which works in EventMachine + Fiber environment.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages