Class: LightIO::Library::SizedQueue
- Defined in:
- lib/lightio/library/sized_queue.rb
Instance Attribute Summary collapse
-
#max ⇒ Object
Returns the value of attribute max.
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(max) ⇒ SizedQueue
constructor
A new instance of SizedQueue.
- #num_waiting ⇒ Object
- #pop(non_block = false) ⇒ Object (also: #deq, #shift)
- #push(object) ⇒ Object (also: #enq, #<<)
Methods inherited from Queue
#close, #closed?, #empty?, #length
Constructor Details
#initialize(max) ⇒ SizedQueue
Returns a new instance of SizedQueue.
7 8 9 10 11 12 |
# File 'lib/lightio/library/sized_queue.rb', line 7 def initialize(max) raise ArgumentError, 'queue size must be positive' unless max > 0 super() @max = max @enqueue_waiters = [] end |
Instance Attribute Details
#max ⇒ Object
Returns the value of attribute max.
5 6 7 |
# File 'lib/lightio/library/sized_queue.rb', line 5 def max @max end |
Instance Method Details
#clear ⇒ Object
37 38 39 40 41 |
# File 'lib/lightio/library/sized_queue.rb', line 37 def clear result = super check_release_enqueue_waiter result end |
#num_waiting ⇒ Object
48 49 50 |
# File 'lib/lightio/library/sized_queue.rb', line 48 def num_waiting super + @enqueue_waiters.size end |
#pop(non_block = false) ⇒ Object Also known as: deq, shift
28 29 30 31 32 |
# File 'lib/lightio/library/sized_queue.rb', line 28 def pop(non_block=false) result = super check_release_enqueue_waiter result end |