Skip to main content
Glama
BlockingStreamObserver.kt891 B
package maestro.utils import io.grpc.stub.StreamObserver import java.util.concurrent.Semaphore import java.util.concurrent.TimeUnit import java.util.concurrent.TimeoutException class BlockingStreamObserver<T> : StreamObserver<T> { private val semaphore = Semaphore(0) private var result: T? = null private var error: Throwable? = null override fun onNext(value: T) { result = value } override fun onError(t: Throwable) { error = t semaphore.release() } override fun onCompleted() { semaphore.release() } fun awaitResult(): T { if (!semaphore.tryAcquire(10, TimeUnit.MINUTES)) { throw TimeoutException("Timeout waiting for Stream to pass Error or Completed message") } error?.let { throw it } return result ?: throw IllegalStateException("Result is missing") } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mobile-dev-inc/Maestro'

If you have feedback or need assistance with the MCP directory API, please join our Discord server