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)因行为不当而臭名昭着,因此不使用它]
使用赛璐珞演员实现这一目标的正确方法是什么?
答案 0 :(得分:0)
shutdown_timeout
的工作方式。 Celluloid.shutdown_timeout
被用来at_exit
来关闭actor。当进程收到终止信号时使用它。
你需要放入Timeout.timeout {}
块,但你是对的,那些行为不端。