赛璐珞演员 - 如何在使用期货时使用Celluloid.shutdown_timeout终止所有演员

时间:2016-03-29 03:07:40

标签: ruby jruby celluloid

require 'celluloid/current'

Celluloid.shutdown_timeout = 1

class Mapper
  include Celluloid

  attr_accessor :value

  def run(num)
      @value = num.times.map { |idx| idx  } 
  end

end

 y = Mapper.spawn
 y.future.run(1000000)

直到现在它似乎工作,演员在1秒后关闭。

  y.value

但是当我尝试访问上面的值时,它会继续,直到方法调用返回的值可用。

我的想法是使用Celluloid.shutdown_timeout,就像标准 Timeout.timeout(1){}

一样

如果超过1秒的时间限制终止该块[ Timeout.timeout(1)因行为不当而臭名昭着,因此不使用它]

使用赛璐珞演员实现这一目标的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

否。这不是shutdown_timeout的工作方式。

当底层进程被终止时,

Celluloid.shutdown_timeout被用来at_exit来关闭actor。当进程收到终止信号时使用它。

你需要放入Timeout.timeout {}块,但你是对的,那些行为不端。