Skip to content

Instantly share code, notes, and snippets.

@neaf
Created July 6, 2011 08:00
Show Gist options
  • Save neaf/1066789 to your computer and use it in GitHub Desktop.
Save neaf/1066789 to your computer and use it in GitHub Desktop.
require "em-http-request"
WORDS = %w( Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce pharetra ullamcorper sodales. Proin nisi velit, venenatis nec dapibus non, molestie quis orci. Etiam eget enim massa, quis ultricies sapien )
module GetGuido
module Jobs
class Http
@queue = :default
def self.perform
EM::run do
pending = 0
20.times do
pending += 1
word = WORDS[pending]
puts "Start: %s" % word
EM::HttpRequest.new("http://www.onet.pl").get.callback do |http|
puts "End: %s" % word
pending -= 1
EM::stop if pending == 0
end
end
end
end
end
end
end
Start: ipsum
Start: dolor
Start: sit
Start: amet,
Start: consectetur
Start: adipiscing
Start: elit.
Start: Fusce
Start: pharetra
Start: ullamcorper
Start: sodales.
Start: Proin
Start: nisi
Start: velit,
Start: venenatis
Start: nec
Start: dapibus
Start: non,
Start: molestie
Start: quis
End: ullamcorper
End: velit,
End: nisi
End: sit
End: adipiscing
End: elit.
End: Proin
End: quis
End: nec
End: non,
End: sodales.
End: Fusce
End: ipsum
End: amet,
End: dolor
End: pharetra
End: consectetur
End: venenatis
End: molestie
End: dapibus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment