Class: Concurrent::WaitableList
- Inherits:
-
Object
- Object
- Concurrent::WaitableList
- Defined in:
- lib/concurrent/channel/waitable_list.rb
Instance Method Summary collapse
- #delete(value) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ WaitableList
constructor
A new instance of WaitableList.
- #put(value) ⇒ Object
- #size ⇒ Object
- #take ⇒ Object
Constructor Details
#initialize ⇒ WaitableList
Returns a new instance of WaitableList.
6 7 8 9 10 11 |
# File 'lib/concurrent/channel/waitable_list.rb', line 6 def initialize @mutex = Mutex.new @condition = Condition.new @list = [] end |
Instance Method Details
#delete(value) ⇒ Object
28 29 30 |
# File 'lib/concurrent/channel/waitable_list.rb', line 28 def delete(value) @mutex.synchronize { @list.delete(value) } end |
#empty? ⇒ Boolean
17 18 19 |
# File 'lib/concurrent/channel/waitable_list.rb', line 17 def empty? @mutex.synchronize { @list.empty? } end |
#put(value) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/concurrent/channel/waitable_list.rb', line 21 def put(value) @mutex.synchronize do @list << value @condition.signal end end |
#size ⇒ Object
13 14 15 |
# File 'lib/concurrent/channel/waitable_list.rb', line 13 def size @mutex.synchronize { @list.size } end |
#take ⇒ Object
32 33 34 35 36 37 |
# File 'lib/concurrent/channel/waitable_list.rb', line 32 def take @mutex.synchronize do @condition.wait(@mutex) while @list.empty? @list.shift end end |