WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ReqT, RespT> forward(call: ServerCall<ReqT, RespT>) :ServerCall<ReqT, RespT> {
return call
}

private inline fun <R> withGrpcContext(context: GrpcContext, action: () -> R): R {
val oldContext: GrpcContext = context.attach()
return try {
Expand All @@ -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)
}
}
}