Class: LightIO::Library::SizedQueue
- Inherits:
-
Queue
- Object
- Queue
- LightIO::Library::SizedQueue
show all
- Defined in:
- lib/lightio/library/sized_queue.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Queue
#close, #closed?, #empty?, #length
Constructor Details
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
|
#push(object) ⇒ Object
Also known as:
enq, <<
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/lightio/library/sized_queue.rb', line 14
def push(object)
raise ClosedQueueError, "queue closed" if @close
if size >= max
future = LightIO::Future.new
@enqueue_waiters << future
future.value
end
super
self
end
|