def find_finished_thread(threads, nonblock)
      if nonblock
        threads.find do |thread|
          !thread.alive?
        end
      else
        if threads.empty?
          raise "No threads to wait for"
        end
        ThreadsWait.new(*threads).next_wait
      end
    end
def find_finished_thread(threads, nonblock)
      if nonblock
        threads.find do |thread|
          !thread.alive?
        end
      else
        if threads.empty?
          raise "No threads to wait for"
        end
        ThreadsWait.new(*threads).next_wait
      end
    end
Check if any of the requested threads are finished.

 @param threads [Array<Thread>]
   The threads to check.
 @param nonblock [Boolean]
   Whether to be non-blocking. If true, nil will be returned if no thread
   is finished. If false, the method will wait until one of the threads
   is finished.

 @return [Thread, nil]
   The finished thread, if any.