Class: Celluloid::Group::Spawner

Inherits:
Celluloid::Group show all
Defined in:
lib/celluloid/group/spawner.rb

Instance Attribute Summary collapse

Attributes inherited from Celluloid::Group

#group

Instance Method Summary collapse

Methods inherited from Celluloid::Group

#active?, #assert_active, #assert_inactive, #create, #each, #each_actor, #forked?, #purge, #to_a

Constructor Details

#initializeSpawner

Returns a new instance of Spawner.



6
7
8
# File 'lib/celluloid/group/spawner.rb', line 6

def initialize
  super
end

Instance Attribute Details

#finalizerObject

Returns the value of attribute finalizer.



4
5
6
# File 'lib/celluloid/group/spawner.rb', line 4

def finalizer
  @finalizer
end

Instance Method Details

#busy?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/celluloid/group/spawner.rb', line 38

def busy?
  to_a.select { |t| t[:celluloid_thread_state] == :running }.any?
end

#get(&block) ⇒ Object

Raises:

  • (ArgumentError)


10
11
12
13
14
# File 'lib/celluloid/group/spawner.rb', line 10

def get(&block)
  assert_active
  raise ArgumentError, "No block sent to Spawner.get()" unless block_given?
  instantiate block
end

#idle?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/celluloid/group/spawner.rb', line 34

def idle?
  to_a.select { |t| t[:celluloid_thread_state] == :running }.empty?
end

#shutdownObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/celluloid/group/spawner.rb', line 16

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