Skip to content

Instantly share code, notes, and snippets.

@bernd
Created January 4, 2013 09:05
Show Gist options
  • Save bernd/4451083 to your computer and use it in GitHub Desktop.
Save bernd/4451083 to your computer and use it in GitHub Desktop.
require 'celluloid'
class URLResolver
include Celluloid
def resolve(num, url)
sleep 1
puts "[#{Time.now.to_f}] #{Thread.current.object_id} #{num} Resolving #{url}"
end
end
Celluloid::Actor[:url_resolver] = URLResolver.pool(size: 5)
20.times.map {|i|
Celluloid::Actor[:url_resolver].future(:resolve, i, 'http://example.com/')
}.map(&:value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment