rubyjrubycelluloid

celluloid actor - how to terminate all actors with Celluloid.shutdown_timeout while using futures


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)

Till now it seems to work and actors are shutdown after 1 second.

  y.value

But the moment I try to access value like above, it goes on till value returned from the method call is available.

My idea was to use Celluloid.shutdown_timeout just like standard Timeout.timeout(1) {}

and terminate the block if it exceeds 1 sec time limit [Timeout.timeout(1) is notorious for misbehaving so not using it]

What's the right way to achieve this using celluloid actors?


Solution

  • No. That is not how shutdown_timeout works.

    Celluloid.shutdown_timeout is used at_exit to shutdown actors when the underlying process is being terminated. It is used when the process receives a kill signal.

    You do need to put Timeout.timeout {} blocks in, but you are right, those do misbehave.