4 # pop(non_block=false, timeout: nil)
6 # Retrieves data from the queue.
8 # If the queue is empty, the calling thread is suspended until data is pushed
9 # onto the queue. If +non_block+ is true, the thread isn't suspended, and
10 # +ThreadError+ is raised.
12 # If +timeout+ seconds have passed and no data is available +nil+ is
13 # returned. If +timeout+ is +0+ it returns immediately.
14 def pop(non_block = false, timeout: nil)
15 if non_block && timeout
16 raise ArgumentError, "can't set a timeout if non_block is enabled"
18 Primitive.rb_queue_pop(non_block, timeout)
20 alias_method :deq, :pop
21 alias_method :shift, :pop
26 # pop(non_block=false, timeout: nil)
28 # Retrieves data from the queue.
30 # If the queue is empty, the calling thread is suspended until data is
31 # pushed onto the queue. If +non_block+ is true, the thread isn't
32 # suspended, and +ThreadError+ is raised.
34 # If +timeout+ seconds have passed and no data is available +nil+ is
35 # returned. If +timeout+ is +0+ it returns immediately.
36 def pop(non_block = false, timeout: nil)
37 if non_block && timeout
38 raise ArgumentError, "can't set a timeout if non_block is enabled"
40 Primitive.rb_szqueue_pop(non_block, timeout)
42 alias_method :deq, :pop
43 alias_method :shift, :pop
46 # push(object, non_block=false, timeout: nil)
47 # enq(object, non_block=false, timeout: nil)
50 # Pushes +object+ to the queue.
52 # If there is no space left in the queue, waits until space becomes
53 # available, unless +non_block+ is true. If +non_block+ is true, the
54 # thread isn't suspended, and +ThreadError+ is raised.
56 # If +timeout+ seconds have passed and no space is available +nil+ is
57 # returned. If +timeout+ is +0+ it returns immediately.
58 # Otherwise it returns +self+.
59 def push(object, non_block = false, timeout: nil)
60 if non_block && timeout
61 raise ArgumentError, "can't set a timeout if non_block is enabled"
63 Primitive.rb_szqueue_push(object, non_block, timeout)
65 alias_method :enq, :push
66 alias_method :<<, :push