Skip to content

Execute GrpcCalls in the provided scope#3569

Open
oldergod wants to merge 1 commit intomasterfrom
bquenaudon.2026-04-15.scope
Open

Execute GrpcCalls in the provided scope#3569
oldergod wants to merge 1 commit intomasterfrom
bquenaudon.2026-04-15.scope

Conversation

@oldergod
Copy link
Copy Markdown
Member

Fixes #3559

@oldergod oldergod requested a review from swankjesse April 15, 2026 08:16
Comment on lines 21 to 194
@@ -117,7 +116,7 @@ fun <S : Any, R : Any> GrpcCall(function: (S) -> R): GrpcCall<S, R> {
* Returns a new instance of [GrpcStreamingCall] that can be used for a single call to
* [executeIn][GrpcStreamingCall.executeIn] or [executeBlocking][GrpcStreamingCall.executeBlocking].
*
* The returned instance launches [function] on [Dispatchers.IO]. The function must close the
* The returned instance launches [function] in the provided scope. The function must close the
* [SendChannel] when it has no more messages to transmit. If [function] throws, both channels will
* be closed using the thrown exception as a cause.
*
@@ -189,7 +188,7 @@ fun <S : Any, R : Any> GrpcStreamingCall(
override fun executeIn(scope: CoroutineScope): Pair<SendChannel<S>, ReceiveChannel<R>> {
check(executed.compareAndSet(false, true)) { "already executed" }

val job = scope.launch(Dispatchers.IO) {
val job = scope.launch {
try {
function(requestChannel, responseChannel)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we add a parameter to GrpcStreamingCall to not break existing callers?

 fun <S : Any, R : Any> GrpcStreamingCall(
+  dispatcher: CoroutineContext = Dispatchers.IO,
   function: suspend (ReceiveChannel<S>, SendChannel<R>) -> Unit,
 ): GrpcStreamingCall<S, R> {

and

-      val job = scope.launch(Dispatchers.IO) {
+      val job = scope.launch(dispatcher) {

@oldergod oldergod marked this pull request as ready for review April 15, 2026 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GrpcStreamingCall() factory's executeIn() hardcodes Dispatchers.IO instead of using an incoming scope

1 participant