Skip to content

Instantly share code, notes, and snippets.

@hackervera
Created September 22, 2010 19:44
Show Gist options
  • Select an option

  • Save hackervera/592384 to your computer and use it in GitHub Desktop.

Select an option

Save hackervera/592384 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'httparty'
def async(arg,wait,callback)
Thread.new {
sleep wait
resp = HTTParty.get(arg)
(wait == 10) ? callback.error("Failed to get resource") : callback.success(resp)
}
end
host = "http://www.google.com"
threads = []
threads << async(host,10,obj)
puts "getting #{host}"
threads << async(host,1,obj)
puts "getting again.."
threads.each {|thr| thr.join }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment