â€ē Async â€ē Source â€ē Async â€ē LimitedQueue

class LimitedQueue

A thread-safe queue which limits the number of items that can be enqueued.

Signature

public

Since Async v1.

Definitions

def self.new(...)

  • private

Signature

private

This exists purely for emitting a warning.

Implementation

def self.new(...)
	warn("`require 'async/limited_queue'` to use `Async::LimitedQueue`.", uplevel: 1, category: :deprecated) if $VERBOSE
	
	super
end

def initialize(limit = 1, **options)

Create a new limited queue.

Signature

parameter limit Integer

The maximum number of items that can be enqueued.

parameter full Notification

The notification to use for signaling when the queue is full. (ignored, for compatibility)

Implementation

def initialize(limit = 1, **options)
	super(**options, delegate: Thread::SizedQueue.new(limit))
end

def limit

Signature

attribute Integer

The maximum number of items that can be enqueued.

Implementation

def limit
	@delegate.max
end

def limited?

Signature

returns Boolean

Whether trying to enqueue an item would block.

Implementation

def limited?
	!@delegate.closed? && @delegate.size >= @delegate.max
end

Discussion