-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function returning ReceiveChannel should not be marked with suspend #30
Comments
Hi @jcornaz, this was introduced in #9 with the reasoning that the handler could make suspending calls to other services. Now in hindsight (and after seeing some more usage of I remember a rule of thumb from some coroutines talk
|
Exactly.
It is possible even if the function is not marked suspend. And that's the point. Example: fun foo(): ReceiveChannel<String> = GlobalScope.produce {
service.doSomethingUseful() // <-- suspending call to another service. It is fine, since we are in a coroutine.
send("Hello")
send("world")
} |
Just to come back on what has been said in #9 by @wfhartford:
I think it does not make sense. Marking a function Returning a Therefore marking a function
This use-case is not valid IMHO for 2 reasons:
suspend fun otherFunctionBadlyDesigned(): ReceiveChannel<String> =...
fun goodFunction(): ReceiveChannel<Int> = produce {
otherFunctionBadlyDesigned().map { it.length }.consumeEach { send(it) }
} |
Regarding my comments in #9, I must have come to the same conclusion that @jcornaz did, that something wasn't very well designed there, since that code is now significantly different. All of my current use-cases of response message streaming use the produce pattern, so do not benefit from the function being marked as |
Since the |
I think there is a mismatch in the documentation currently because the readme is documenting the new style available in the @voidzcy, here is the version of the readme you want to read: https://github.com/rouzwawi/grpc-kotlin/blob/v0.1.0/README.md |
@jcornaz Cool. Thanks. |
Hello,
May I ask why the functions returning
ReceiveChannel
are marked withsuspend
?This is not necessary and a bit confusing.
Here is what I would personnaly expect:
The text was updated successfully, but these errors were encountered: