Class: LightIO::Library::SizedQueue
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Queue
#close, #closed?, #empty?, #length
Constructor Details
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
|
#push(object) ⇒ Object
Also known as:
enq, <<
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/lightio/library/sized_queue.rb', line 17
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
|