def wait_for_threaded_commands(options = {})
      options[:which] ||= @threaded_commands
      threads = options[:which].map(&:thread)
      if finished_thread = find_finished_thread(threads, options[:nonblock])
        threaded_command = @threaded_commands.find do |tc|
          tc.thread == finished_thread
        end
        @threaded_commands.delete(threaded_command)
        threaded_command
      end
    end
def wait_for_threaded_commands(options = {})
      options[:which] ||= @threaded_commands
      threads = options[:which].map(&:thread)
      if finished_thread = find_finished_thread(threads, options[:nonblock])
        threaded_command = @threaded_commands.find do |tc|
          tc.thread == finished_thread
        end
        @threaded_commands.delete(threaded_command)
        threaded_command
      end
    end
Wait for threaded commands to complete.

 @param options [Hash]
   Options.
 @option options [Set<ThreadedCommand>, Array<ThreadedCommand>] :which
   Which {ThreadedCommand} objects to wait for. If not specified, this
   method will wait for any.
 @option options [Boolean] :nonblock
   Set to true to not block.

 @return [ThreadedCommand, nil]
   The {ThreadedCommand} object that is finished.