Class: Thread::Queue
Instance Method Summary collapse
- #clear ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ Queue
constructor
A new instance of Queue.
- #pop(non_block = false) ⇒ Object (also: #deq, #shift)
- #push(value) ⇒ Object (also: #<<, #enq)
- #size ⇒ Object (also: #length)
Constructor Details
#initialize ⇒ Queue
Returns a new instance of Queue.
73 74 75
# File 'opal/stdlib/thread.rb', line 73 def initialize clear end
Instance Method Details
#clear ⇒ Object
77 78 79
# File 'opal/stdlib/thread.rb', line 77 def clear @storage = [] end
#each(&block) ⇒ Object
102 103 104
# File 'opal/stdlib/thread.rb', line 102 def each(&block) @storage.each(&block) end
#empty? ⇒ Boolean
Returns:
- (Boolean )
81 82 83
# File 'opal/stdlib/thread.rb', line 81 def empty? @storage.empty? end
#pop(non_block = false) ⇒ Object Also known as: deq, shift
89 90 91 92 93 94 95 96
# File 'opal/stdlib/thread.rb', line 89 def pop(non_block = false) if empty? raise ThreadError , 'Queue empty' if non_block raise ThreadError , 'Deadlock' end @storage.shift end
#push(value) ⇒ Object Also known as: <<, enq
98 99 100
# File 'opal/stdlib/thread.rb', line 98 def push(value) @storage.push(value) end
#size ⇒ Object Also known as: length
85 86 87
# File 'opal/stdlib/thread.rb', line 85 def size @storage.size end