class Async::LimitedQueue

@public Since ‘stable-v1`.

def <<(item)

def <<(item)
	while limited?
		@full.wait
	end
	
	super
end

def dequeue

def dequeue
	item = super
	
	@full.signal
	
	return item
end

def enqueue *items

def enqueue *items
	while !items.empty?
		while limited?
			@full.wait
		end
		
		available = @limit - @items.size
		@items.concat(items.shift(available))
		
		self.signal unless self.empty?
	end
end

def initialize(limit = 1, **options)

def initialize(limit = 1, **options)
	super(**options)
	
	@limit = limit
	
	@full = Notification.new
end

def limited?

@returns [Boolean] Whether trying to enqueue an item would block.

def limited?
	@items.size >= @limit
end