赛璐珞监督组不起作用

时间:2015-10-31 01:02:09

标签: ruby celluloid

我编写以下脚本以了解赛璐珞。

require 'celluloid/current'

class Processor
  include Celluloid

  def perfom(number)
    puts "#{number} ... (#{Thread.current}) ..."
    sleep(number%3)
    puts "Launch finish!"
    return number
  end
end

pool = Processor.pool(size: 3)

futures = (1..7).map do |i|
  pool.future(:perfom, i)
end
puts futures.map(&:value)

pool.terminate

一切正常,我想避免在游泳池上调用终止。

所以我尝试使用主管,但它引起了我uninitialized constant Celluloid::SupervisionGroup

搜索后,我发现这个(在已弃用的文件夹中):( https://github.com/celluloid/celluloid-supervision/blob/master/spec/celluloid/deprecate/supervision/supervision_group_spec.rb

我想做的工作如下:

supervisor = Celluloid::SupervisionGroup.run!
pool       = supervisor.pool(Processor, size: 3, as: :worker)

futures = (1..7).map do |i|
  pool[:worker].future(:perfom, i)
end
puts futures.map(&:value)

如何使用新系统开展未来,主管和游泳池的工作?

1 个答案:

答案 0 :(得分:2)

Celluloid :: SupervisionGroup 重命名为 Celluloid :: Supervision :: Container

请参阅https://github.com/celluloid/celluloid/wiki/DEPRECATION-WARNING