Skip to content

Instantly share code, notes, and snippets.

@cktricky
Created September 30, 2012 01:33
Show Gist options
  • Save cktricky/3805592 to your computer and use it in GitHub Desktop.
Save cktricky/3805592 to your computer and use it in GitHub Desktop.
Cool proc-ness
#!/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