Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save hackervera/592389 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"
class RandObj
def success(resp)
puts resp
end
def error(resp)
puts resp
end
end
def chow
puts "chow fun" # LOL
puts yield(5)
end
def bee
puts "bee fun"
end
obj = RandObj.new
threads = []
threads << async(host,10,obj)
puts "getting #{host}"
threads << async(host,1,obj)
puts "getting again.."
threads.each {|thr| thr.join }
foo = (1..4)
proc = Proc.new {|x| y =2; x + y}
foo.each{|number| chow(&proc) }
#Thread.stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment