-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Introduce awaitReceive and awaitReceiveOrNull APIs #31188
Introduce awaitReceive and awaitReceiveOrNull APIs #31188
Conversation
This commit introduces awaitReceive/awaitReceiveOrNull as a replacement for awaitBody/awaitBodyOrNull and explains the rationale behind it. Closes spring-projectsgh-30926 Signed-off-by: George Papadopoulos <[email protected]>
7d884f2
to
5f5144a
Compare
Thanks for providing this PR, but I don't think we should merge the proposed changes.
Please refer for this comment for related feedback about current APIs and related documentation and see #31189 follow-up issue.
I don't think this is correct, For those reasons, I decline this PR, but thanks for the discussion. |
Hey, thanks for the feedback!
I agree with this statement. I tried to raise the issue about the naming in the function itself So in the same manner, imo, i expect a function named |
As far as I know, |
I was checking the deprecation section here: Deprecation note.
But that might be also the case. I cannot argue here since I'm not expert in coroutines. |
Interesting, the deprecation may be partially misleading because as far as I can tell |
I'm quite interested as well in what the kotlin team has to say. Nevertheless, I will drop my two cents just for the sake of the discussion: From my understanding most coroutines operators propagate (and throw) all exceptions Examples:
|
We got confirmation from the Kotlin team the wording from the deprecation notes is misleading. |
I see, nevertheless, thanks for the discussion. |
Summary
ServerRequest.awaitBody*
APIs have some problems:ServerRequest.awaitBody
forces you to think about the coroutines-bridge exception handling, since it useskotlinx.coroutines.reactive.awaitSingle
. Also, it is not documented that it might throwNoSuchElementException
and
IllegalArgumentException
for coroutines-related errors.ServerRequest.awaitBody
might throwIllegalArgumentException
for two different reasons, for serialization-relatederrors and for coroutines-related errors.
ServerRequest.awaitBodyOrNull
should never throw as the signature indicates. The convention established by thestdlib mandate that an operation with the name
xxxOrNull
returnsnull
instead of throwing in case there is anerror.
Proposal
Introduce APIs that address all the above.
Add
ServerRequest.awaitReceiveNullable
.null
in case user is expecting the body to be "missing"Add
ServerRequest.awaitReceive
.Both APIs introduce a "mindset" that only serialization-wise can something go wrong, in other words, user input.
Extensions:
Based on these functions, the user can create their own function for a general catch-all and return
null
patternDeprecations/Migrations
Deprecate
ServerRequest.awaitBodyOrNull
which can be replaced withServerRequest.awaitReceiveNullable
, asbehavior wise they are pretty close.
Deprecate
ServerRequest.awaitBody
with not direct replacement, but promote the usage ofServerRequest.awaitReceive
.Closes gh-30926