pop(non_block = false) -> object
[permalink][rdoc]shift(non_block = false) -> object
deq(non_block = false) -> object
キューからひとつ値を取り出します。キューに push しようと待っているスレッドがあれば、実行を再開させます。
require 'thread'
q = SizedQueue.new(4)
th1 = Thread.start do
while resource = q.pop
puts resource
end
end
[:resource1, :resource2, :resource3, nil].each{|r|
q.push(r)
}
th1.join
# => resource1
# resource2
# resource3
require 'thread'
q = SizedQueue.new(4)
th1 = Thread.start do
while resource = q.pop
puts resource
end
end
[:resource1, :resource2, :resource3, nil].each{|r|
q.push(r)
}
begin
th1.join
q.pop(true)
rescue => e
p e
p e.message
end
# => resource1
# resource2
# resource3
# => #<ThreadError: queue empty>
# => "queue empty"
[SEE_ALSO] Thread::Queue#pop