class Async::LimitedQueue
@public Since *Async v1*.
A queue which limits the number of items that can be enqueued.
def <<(item)
If the queue is full, this method will block until there is space available.
Add an item to the queue.
def <<(item) while limited? @full.wait end super end
def dequeue
If the queue is empty, this method will block until an item is available.
Remove and return the next item from the queue.
def dequeue item = super @full.signal return item end
def enqueue(*items)
If the queue is full, this method will block until there is space available.
Add multiple items to the queue.
def enqueue(*items) while !items.empty? while limited? @full.wait end available = @limit - @items.size @items.concat(items.shift(available)) @available.signal unless self.empty? end end
def initialize(limit = 1, full: Notification.new, **options)
@parameter limit [Integer] The maximum number of items that can be enqueued.
Create a new limited queue.
def initialize(limit = 1, full: Notification.new, **options) super(**options) @limit = limit @full = full end
def limited?
def limited? @items.size >= @limit end