Class: LightIO::Library::SizedQueue
- Extended by:
- Base::MockMethods
- 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.
10 11 12 13 14 15 |
# File 'lib/lightio/library/sized_queue.rb', line 10 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.
8 9 10 |
# File 'lib/lightio/library/sized_queue.rb', line 8 def max @max end |
Instance Method Details
#clear ⇒ Object
40 41 42 43 44 |
# File 'lib/lightio/library/sized_queue.rb', line 40 def clear result = super check_release_enqueue_waiter result end |
#num_waiting ⇒ Object
51 52 53 |
# File 'lib/lightio/library/sized_queue.rb', line 51 def num_waiting super + @enqueue_waiters.size end |
#pop(non_block = false) ⇒ Object Also known as: deq, shift
31 32 33 34 35 |
# File 'lib/lightio/library/sized_queue.rb', line 31 def pop(non_block=false) result = super check_release_enqueue_waiter result end |