Skip to content

Commit 3754417

Browse files
committed
Launch SendMessage coroutine with CoroutineStart.UNDISPATCHED.
Especially, this improves performance when the current dispatcher is `Dispatchers.Main`.
1 parent 0681fc8 commit 3754417

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

stub/src/main/java/io/grpc/kotlin/ClientCalls.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ import io.grpc.MethodDescriptor
2222
import io.grpc.Status
2323
import kotlinx.coroutines.CancellationException
2424
import kotlinx.coroutines.CoroutineName
25+
import kotlinx.coroutines.CoroutineStart
2526
import kotlinx.coroutines.NonCancellable
2627
import kotlinx.coroutines.cancel
2728
import kotlinx.coroutines.channels.Channel
2829
import kotlinx.coroutines.channels.onFailure
2930
import kotlinx.coroutines.coroutineScope
3031
import kotlinx.coroutines.flow.Flow
31-
import kotlinx.coroutines.flow.collect
3232
import kotlinx.coroutines.flow.flow
3333
import kotlinx.coroutines.launch
3434
import kotlinx.coroutines.withContext
@@ -309,7 +309,10 @@ object ClientCalls {
309309
headers.copy()
310310
)
311311

312-
val sender = launch(CoroutineName("SendMessage worker for ${method.fullMethodName}")) {
312+
val sender = launch(
313+
context = CoroutineName("SendMessage worker for ${method.fullMethodName}"),
314+
start = CoroutineStart.UNDISPATCHED
315+
) {
313316
try {
314317
request.sendTo(clientCall, readiness)
315318
clientCall.halfClose()

0 commit comments

Comments
 (0)