Ruby 2.6.0 リファレンスマニュアル > ライブラリ一覧 > thwaitライブラリ > ThreadsWaitクラス > next_wait

instance method ThreadsWait#next_wait

next_wait(nonblock = nil) -> Thread[permalink][rdoc]

指定したスレッドのどれかが終了するまで待ちます。

[PARAM] nonblock:
true を与えると、キューが空の時、例外 ThreadsWait::ErrNoFinishedThread が発生します。
[EXCEPTION] ErrNoWaitingThread:
終了をまつスレッドが存在しない時、発生します。
[EXCEPTION] ErrNoFinishedThread:
nonblock がtrue でかつ、キューが空の時、発生します。
#使用例
require 'thwait'

threads = []
2.times {|i|
  threads << Thread.new { sleep i }
}

thall = ThreadsWait.new
thall.join_nowait(*threads)
until thall.empty?
  th = thall.next_wait
  p th
end

[SEE_ALSO] Queue#pop