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)是因为行为不当而不使用它。
用电影演员来实现这一目标的正确方法是什么?
发布于 2016-04-05 18:20:23
不是的。这不是shutdown_timeout的工作方式。
当基础进程被终止时,Celluloid.shutdown_timeout被使用at_exit关闭参与者。当进程接收到杀死信号时,就会使用它。
您确实需要放置Timeout.timeout {}块,但您是对的,这些都是不正确的。
https://stackoverflow.com/questions/36274677
复制相似问题