class LightIO::Library::ThreadsWait
Constants
- ErrNoFinishedThread
- ErrNoWaitingThread
Attributes
threads[R]
Public Class Methods
new(*threads)
click to toggle source
# File lib/lightio/library/threads_wait.rb, line 15 def initialize(*threads) @threads = threads end
Public Instance Methods
all_waits() { |thr| ... }
click to toggle source
# File lib/lightio/library/threads_wait.rb, line 19 def all_waits until empty? thr = next_wait yield thr if block_given? end end
empty?()
click to toggle source
# File lib/lightio/library/threads_wait.rb, line 26 def empty? @threads.empty? end
finished?()
click to toggle source
# File lib/lightio/library/threads_wait.rb, line 30 def finished? @threads.any? {|thr| !thr.alive?} end
join(*threads)
click to toggle source
# File lib/lightio/library/threads_wait.rb, line 34 def join(*threads) join_nowait(*threads) next_wait end
join_nowait(*threads)
click to toggle source
# File lib/lightio/library/threads_wait.rb, line 39 def join_nowait(*threads) @threads.concat(threads) end
next_wait(nonblock=nil)
click to toggle source
# File lib/lightio/library/threads_wait.rb, line 43 def next_wait(nonblock=nil) raise ::ThreadsWait::ErrNoWaitingThread, 'No threads for waiting.' if empty? @threads.each do |thr| if thr.alive? && nonblock next elsif thr.alive? thr.join end # thr should dead @threads.delete(thr) return thr end raise ::ThreadsWait::ErrNoFinishedThread, 'No finished threads.' end