Skip to content

Commit

Permalink
Launch SendMessage coroutine with CoroutineStart.UNDISPATCHED.
Browse files Browse the repository at this point in the history
Especially, this improves performance when the current dispatcher is `Dispatchers.Main`.
  • Loading branch information
yamasa committed Jul 31, 2022
1 parent 0681fc8 commit 3754417
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions stub/src/main/java/io/grpc/kotlin/ClientCalls.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import io.grpc.MethodDescriptor
import io.grpc.Status
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.cancel
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.onFailure
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -309,7 +309,10 @@ object ClientCalls {
headers.copy()
)

val sender = launch(CoroutineName("SendMessage worker for ${method.fullMethodName}")) {
val sender = launch(
context = CoroutineName("SendMessage worker for ${method.fullMethodName}"),
start = CoroutineStart.UNDISPATCHED
) {
try {
request.sendTo(clientCall, readiness)
clientCall.halfClose()
Expand Down

0 comments on commit 3754417

Please sign in to comment.