Class Methods

Creates a new queue instance.

Instance Methods
An alias for push

Removes all objects from the queue.

Closes the queue. A closed queue cannot be re-opened.

After the call to close completes, the following are true:

  • closed? will return true

  • close will be ignored.

  • calling enq/push/<< will return nil.

  • when empty? is false, calling deq/pop/shift will return an object from the queue as usual.

ClosedQueueError is inherited from StopIteration, so that you can break loop block.

Example:

    q = Queue.new
    Thread.new{
      while e = q.deq # wait for nil to break loop
        # ...
      end
    }
    q.close

Returns true if the queue is closed.

An alias for pop

Returns true if the queue is empty.

An alias for push

Returns the length of the queue.

Returns the number of threads waiting on the queue.

Retrieves data from the queue.

If the queue is empty, the calling thread is suspended until data is pushed onto the queue. If non_block is true, the thread isn’t suspended, and ThreadError is raised.

Pushes the given object to the queue.

An alias for pop
An alias for length