Created
September 22, 2010 19:46
-
-
Save hackervera/592389 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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