Name
Queue — Message queue class
Synopsis
This class provides the way to communicate data between threads.
Required Library
require ‘thread’
Class Method
Queue::new
Creates a
queue
object
Instance Methods
q
.empty?
Returns
true
if the queue is empty.q
.num_waiting
Returns the number of threads waiting on the queue.
q
.pop([
non_block
=false])
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
istrue
, the thread isn’t suspended, and an exception is raised.q
.push(
obj
)
q
.enq(
obj
)
Pushes
obj
to the queue.q
.size
q
.length
Returns the length of the queue.
Get Ruby in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.