[fleet] reformat, dead code

GitOrigin-RevId: 11175e0ad26c8d37505e087eda48133c89c8e89e
This commit is contained in:
Alexander Shparun
2024-09-18 04:46:41 +02:00
committed by intellij-monorepo-bot
parent 5c53a163d6
commit 137ee8f6af

View File

@@ -18,17 +18,21 @@ enum class EndpointKind {
}
interface RequestDispatcher {
suspend fun handleConnection(route: UID,
endpoint: EndpointKind,
presentableName: String? = null,
send: SendChannel<TransportMessage>,
receive: ReceiveChannel<TransportMessage>)
suspend fun handleConnection(
route: UID,
endpoint: EndpointKind,
presentableName: String? = null,
send: SendChannel<TransportMessage>,
receive: ReceiveChannel<TransportMessage>,
)
}
suspend fun RequestDispatcher.serveRpc(route: UID,
json: () -> Serialization,
services: RpcServiceLocator,
interceptor: RpcExecutorMiddleware = RpcExecutorMiddleware) {
suspend fun RequestDispatcher.serveRpc(
route: UID,
json: () -> Serialization,
services: RpcServiceLocator,
interceptor: RpcExecutorMiddleware = RpcExecutorMiddleware,
) {
val dispatcher = this
spannedScope("serveRpc") {
val (dispatcherSend, executorReceive) = channels<TransportMessage>(Channel.BUFFERED)
@@ -49,30 +53,3 @@ suspend fun RequestDispatcher.serveRpc(route: UID,
}
}
}
private data class Handle<out T>(private val deferred: Deferred<T>, private val job: Job) {
suspend fun await(): T = deferred.await()
suspend fun join(): Unit = job.join()
fun cancel(cause: CancellationException?): Unit = job.cancel(cause)
}
private fun <T> CoroutineScope.handle(body: suspend CoroutineScope.(suspend (T) -> Unit) -> Unit): Handle<T> {
val deferred = CompletableDeferred<T>()
val job = launch(start = CoroutineStart.ATOMIC) {
body { t ->
check(deferred.complete(t)) { "Subsequent invocations make no sense" }
awaitCancellation()
}
}.apply {
invokeOnCompletion { cause ->
if (cause != null) {
deferred.completeExceptionally(cause)
}
else {
deferred.completeExceptionally(RuntimeException("job has finished"))
}
}
}
return Handle(deferred, job)
}