public void waitFor(InterceptedStream<T> stream) {

        T underlyingStream = stream.getStream();

        // Wait for stream to close
        synchronized (underlyingStream) {
            while (streams.get(stream.getIndex()) == stream) {
                try {
                    underlyingStream.wait(STREAM_WAIT_TIMEOUT);
                }
                catch (InterruptedException e) {
                    // Ignore
                }
            }
        }

    }
Blocks until the given stream is closed, or until another stream with
the same index replaces it.

@param stream
    The stream to wait for.
guacamole/src/main/java/org/apache/guacamole/tunnel/InterceptedStreamMap.java