class method
Thread::Queue.new
[Elem = untyped] () -> ::Thread::Queue[Elem]
Thread::Queue.new → empty_queue
Thread::Queue.new(enumerable) → queue
thread_sync.c
View on GitHub ↗
static VALUE
rb_queue_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE initial;
struct rb_queue *q = queue_ptr(self);
if ((argc = rb_scan_args(argc, argv, "01", &initial)) == 1) {
initial = rb_to_array(initial);
}
RB_OBJ_WRITE(self, queue_list(q), ary_buf_new());
ccan_list_head_init(queue_waitq(q));
if (argc == 1) {
rb_ary_concat(q->que, initial);
}
return self;
}
Creates a new queue instance, optionally using the contents of an enumerable for its initial state.
Example:
Example
q = Thread::Queue.new #=> #<Thread::Queue:0x00007ff7501110d0> q.empty? #=> true q = Thread::Queue.new([1, 2, 3]) #=> #<Thread::Queue:0x00007ff7500ec500> q.empty? #=> false q.pop #=> 1
Ruby version changes
-
3.1
-
Thread::Queue.newnow accepts anEnumerableof initial values. [Feature #17327]
-