Class: Celluloid::Group
- Inherits:
-
Object
- Object
- Celluloid::Group
- Defined in:
- lib/celluloid/group.rb,
lib/celluloid/group/pool.rb,
lib/celluloid/group/spawner.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#group ⇒ Object
Returns the value of attribute group.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #assert_active ⇒ Object
- #assert_inactive ⇒ Object
- #create ⇒ Object
- #each ⇒ Object
- #each_actor(&block) ⇒ Object
- #get ⇒ Object
-
#initialize ⇒ Group
constructor
A new instance of Group.
- #purge(thread) ⇒ Object
- #shutdown ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize ⇒ Group
5 6 7 8 9 |
# File 'lib/celluloid/group.rb', line 5 def initialize @mutex = Mutex.new @group = [] @running = true end |
Instance Attribute Details
#group ⇒ Object
Returns the value of attribute group.
3 4 5 |
# File 'lib/celluloid/group.rb', line 3 def group @group end |
Instance Method Details
#active? ⇒ Boolean
45 46 47 |
# File 'lib/celluloid/group.rb', line 45 def active? @running end |
#assert_active ⇒ Object
11 12 13 |
# File 'lib/celluloid/group.rb', line 11 def assert_active fail Celluloid::NotActive unless active? end |
#assert_inactive ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/celluloid/group.rb', line 15 def assert_inactive return unless active? if RUBY_PLATFORM == "java" Celluloid.logger.warn "Group is still active" else fail Celluloid::StillActive end end |
#create ⇒ Object
53 54 55 |
# File 'lib/celluloid/group.rb', line 53 def create fail NotImplementedError end |
#each ⇒ Object
24 25 26 |
# File 'lib/celluloid/group.rb', line 24 def each to_a.each { |thread| yield thread } end |
#each_actor(&block) ⇒ Object
41 42 43 |
# File 'lib/celluloid/group.rb', line 41 def each_actor(&block) to_a.lazy.select { |t| t[:celluloid_role] == :actor }.each(&block) end |
#get ⇒ Object
49 50 51 |
# File 'lib/celluloid/group.rb', line 49 def get fail NotImplementedError end |
#purge(thread) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/celluloid/group.rb', line 34 def purge(thread) @mutex.synchronize do @group.delete(thread) thread.kill rescue nil end end |
#shutdown ⇒ Object
57 58 59 |
# File 'lib/celluloid/group.rb', line 57 def shutdown fail NotImplementedError end |
#to_a ⇒ Object
28 29 30 31 32 |
# File 'lib/celluloid/group.rb', line 28 def to_a res = nil @mutex.synchronize { res = @group.dup } res end |