What I did after all, is change the AggregatorActor
to have a wait_for_results
:
class AggregatorActor
include Celluloid
def initialize(shufflers)
@shufflerset = shufflers
@results = {}
end
def wait_for_results
sleep 5 while not @shufflerset.empty?
self.output
self.terminate
end
def add_result(result)
@results.merge! result
@shufflerset = @shufflerset - result.keys
puts "Results for #{result.keys.inspect} recorded, remaining: #{@shufflerset.inspect}"
end
def output
puts @results
end
end
And then I got rid of the SupervisionGroup
(since I didn't need supervision, ie rerunning of actors that failed), and I used it like this:
shufflers = [RubyShuffler, PileShuffle, VariablePileShuffle, VariablePileShuffleHuman, RiffleShuffle].to_set
Celluloid::Actor[:aggregator] = AggregatorActor.new(shufflers.map { |sh| sh.new.name })
shufflers.each do |shuffler|
Celluloid::Actor[shuffler.name.to_sym] = EvalActor.new shuffler
end
Celluloid::Actor[:aggregator].wait_for_results
That doesn't feel very clean, it would be nice if there was a cleaner way, but at least this works.