class LightIO::Library::SizedQueue

Attributes

max[RW]

Private Class Methods

new(max) click to toggle source
Calls superclass method LightIO::Library::Queue::new
# 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

Private Instance Methods

<<(object)
Alias for: push
check_release_enqueue_waiter() click to toggle source
# File lib/lightio/library/sized_queue.rb, line 56
def check_release_enqueue_waiter
  if @enqueue_waiters.any?
    future = LightIO::Future.new
    LightIO::IOloop.current.add_callback {
      @enqueue_waiters.shift.transfer
      future.transfer
    }
    future.value
  end
end
clear() click to toggle source
Calls superclass method LightIO::Library::Queue#clear
# File lib/lightio/library/sized_queue.rb, line 40
def clear
  result = super
  check_release_enqueue_waiter
  result
end
deq(non_block=false)
Alias for: pop
enq(object)
Alias for: push
max=(value) click to toggle source
# File lib/lightio/library/sized_queue.rb, line 46
def max=(value)
  @max = value
  check_release_enqueue_waiter if size < max
end
num_waiting() click to toggle source
Calls superclass method LightIO::Library::Queue#num_waiting
# File lib/lightio/library/sized_queue.rb, line 51
def num_waiting
  super + @enqueue_waiters.size
end
pop(non_block=false) click to toggle source
Calls superclass method LightIO::Library::Queue#pop
# File lib/lightio/library/sized_queue.rb, line 31
def pop(non_block=false)
  result = super
  check_release_enqueue_waiter
  result
end
Also aliased as: deq, shift
push(object) click to toggle source
Calls superclass method LightIO::Library::Queue#push
# 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
Also aliased as: enq, <<
shift(non_block=false)
Alias for: pop