Class: Agent::WaitGroup
- Inherits:
-
Object
- Object
- Agent::WaitGroup
- Defined in:
- lib/agent/wait_group.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
Instance Method Summary collapse
- #add(delta) ⇒ Object
- #done ⇒ Object
-
#initialize ⇒ WaitGroup
constructor
A new instance of WaitGroup.
- #wait ⇒ Object
Constructor Details
#initialize ⇒ WaitGroup
Returns a new instance of WaitGroup.
7 8 9 10 11 |
# File 'lib/agent/wait_group.rb', line 7 def initialize @count = 0 @mutex = Mutex.new @cvar = ConditionVariable.new end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
5 6 7 |
# File 'lib/agent/wait_group.rb', line 5 def count @count end |
Instance Method Details
#add(delta) ⇒ Object
21 22 23 24 25 |
# File 'lib/agent/wait_group.rb', line 21 def add(delta) @mutex.synchronize do modify_count(delta) end end |
#done ⇒ Object
27 28 29 30 31 |
# File 'lib/agent/wait_group.rb', line 27 def done @mutex.synchronize do modify_count(-1) end end |
#wait ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/agent/wait_group.rb', line 13 def wait @mutex.synchronize do while @count > 0 @cvar.wait(@mutex) end end end |