class Celluloid::Group::Spawner
Attributes
finalizer[RW]
Public Class Methods
new()
click to toggle source
Calls superclass method
Celluloid::Group.new
# File lib/celluloid/group/spawner.rb, line 8 def initialize super end
Public Instance Methods
busy?()
click to toggle source
# File lib/celluloid/group/spawner.rb, line 40 def busy? to_a.select { |t| t[:celluloid_thread_state] == :running }.any? end
get(&block)
click to toggle source
# File lib/celluloid/group/spawner.rb, line 12 def get(&block) assert_active fail ArgumentError.new("No block sent to Spawner.get()") unless block_given? instantiate block end
idle?()
click to toggle source
# File lib/celluloid/group/spawner.rb, line 36 def idle? to_a.select { |t| t[:celluloid_thread_state] == :running }.empty? end
shutdown()
click to toggle source
# File lib/celluloid/group/spawner.rb, line 18 def shutdown @running = false queue = [] @mutex.synchronize do loop do break if @group.empty? th = @group.shift th.kill queue << th end end Thread.pass unless queue.empty? loop do break if queue.empty? queue.pop.join end end
Private Instance Methods
instantiate(proc)
click to toggle source
# File lib/celluloid/group/spawner.rb, line 46 def instantiate(proc) thread = Thread.new do Thread.current[:celluloid_thread_state] = :running begin proc.call rescue ::Exception => ex Internals::Logger.crash("thread crashed", ex) Thread.current[:celluloid_thread_state] = :error ensure unless Thread.current[:celluloid_thread_state] == :error Thread.current[:celluloid_thread_state] = :finished end @mutex.synchronize { @group.delete Thread.current } Thread.exit end end @mutex.synchronize { @group << thread } thread end