2016-03-29 57 views
1
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秒后关机终止与Celluloid.shutdown_timeout所有演员。赛璐珞演员 - 如何在使用期货

y.value 

但是,当我尝试访问像上面那样的值时,它一直持续到方法调用返回的值可用。

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

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

什么是正确的方式来实现这个使用赛璐珞演员?

回答

0

不,那不是shutdown_timeout的工作原理。

Celluloid.shutdown_timeout用于at_exit在底层进程终止时关闭参与者。它在进程收到kill信号时使用。

你确实需要把Timeout.timeout {}块,但你是对的,那些做错了。