Created
September 30, 2012 01:33
-
-
Save cktricky/3805592 to your computer and use it in GitHub Desktop.
Cool proc-ness
This file contains 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
#!/usr/bin/env ruby | |
require 'celluloid' | |
require 'net/http' | |
class Fetcher | |
include Celluloid | |
def get(action, url) | |
puts "doing work.." | |
res = action.call(url) | |
return res | |
rescue Exception => e | |
return "" | |
end | |
end | |
urls = Array.new(1000, "http://www.cnn.com") | |
pool = Fetcher.pool(size: 100); urls.map { |url| | |
pool.future.get(Proc.new {|x| Net::HTTP.get URI(x)}, url) | |
}.map(&:value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment