Skip to content

Instantly share code, notes, and snippets.

@bmarini
Created May 2, 2011 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmarini/951782 to your computer and use it in GitHub Desktop.
Save bmarini/951782 to your computer and use it in GitHub Desktop.
Playing around with EM
require 'rubygems'
require 'bundler/setup'
require 'eventmachine'
require 'httparty'
# Serial Processing:
# results = %[realtime forker].collect do |path|
# HTTParty.get "http://github.com/api/v2/json/repos/show/#{path}"
# end
#
# p results.map { |r| r['repository']['name'] }
# Parallel Processing:
results = []
EM.run do
add_result = lambda { |result| results.push(result) }
repo_paths.each do |path|
EM.defer( lambda { "http://github.com/api/v2/json/repos/show/#{path}" }, add_result )
end
EM.add_periodic_timer(0.1) do
EM.stop if results.size == repo_paths.size
end
end
p results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment