Created
April 9, 2012 09:36
-
-
Save pangloss/2342518 to your computer and use it in GitHub Desktop.
Worker pool does not limit the number of workers created
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 'celluloid' | |
class Counter | |
include Celluloid::Worker | |
def count | |
len = rand(1000) | |
Celluloid::Actor[:min].result len | |
len | |
end | |
end | |
class Min | |
include Celluloid | |
attr_reader :min | |
def result(n) | |
@min ||= n | |
@min = n if n < @min | |
end | |
end | |
pool = Counter.pool | |
min = Min.new | |
Celluloid::Actor[:min] = min | |
Celluloid::Actor[:pool] = pool | |
puts "Number of actors: #{ Celluloid::Actor.all.length }" | |
50.times { | |
pool.count! | |
} | |
sleep 1 | |
puts "Number of actors: #{ Celluloid::Actor.all.length }" | |
100.times { | |
pool.count! | |
} | |
sleep 3 | |
puts "Number of actors: #{ Celluloid::Actor.all.length }" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment