From b2d6d72dc3a15bfd1bca28c10e80d1bfeebd0d43 Mon Sep 17 00:00:00 2001 From: "Daniel M. Weeks" Date: Wed, 11 Jan 2023 17:02:56 -0500 Subject: [PATCH] CoroutineContextServerInterceptor method to apply a ForwardingServerCall --- .../io/grpc/kotlin/CoroutineContextServerInterceptor.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/stub/src/main/java/io/grpc/kotlin/CoroutineContextServerInterceptor.kt b/stub/src/main/java/io/grpc/kotlin/CoroutineContextServerInterceptor.kt index f81063eb..9d46dc54 100644 --- a/stub/src/main/java/io/grpc/kotlin/CoroutineContextServerInterceptor.kt +++ b/stub/src/main/java/io/grpc/kotlin/CoroutineContextServerInterceptor.kt @@ -40,6 +40,13 @@ abstract class CoroutineContextServerInterceptor : ServerInterceptor { */ abstract fun coroutineContext(call: ServerCall<*, *>, headers: Metadata): CoroutineContext + /** + * Override this function to insert a forwarding server call. + */ + open fun forward(call: ServerCall) :ServerCall { + return call + } + private inline fun withGrpcContext(context: GrpcContext, action: () -> R): R { val oldContext: GrpcContext = context.attach() return try { @@ -61,7 +68,7 @@ abstract class CoroutineContextServerInterceptor : ServerInterceptor { throw e } return withGrpcContext(GrpcContext.current().extendCoroutineContext(coroutineContext)) { - next.startCall(call, headers) + next.startCall(forward(call), headers) } } } \ No newline at end of file