Skip to content
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

Request awaitSingleOrNull for reactive #2088

Closed
JasonMing opened this issue Jun 12, 2020 · 5 comments
Closed

Request awaitSingleOrNull for reactive #2088

JasonMing opened this issue Jun 12, 2020 · 5 comments
Labels

Comments

@JasonMing
Copy link

kotlin-coroutines awaitSingle() can assert the Flux contains one and only one element and returning first element.
But seems there is no operators can assert the Flux contains zero or one element, i.e., awaitSingleOrNull().

@elizarov
Copy link
Contributor

Also related to #2079

@dkhalanskyjb
Copy link
Collaborator

Hi @JasonMing! In fact, a method with that same name has been present for a while as an extension on arbitrary Publisher, but we decided to deprecate that method, as it has a confusing name: "xOrY" in Kotlin typically means that if the operation finishes with an error, then "Y" will be returned instead, but for awaitSingleOrNull, this would require that null is returned in cases of both zero elements and more than one element, which can be surprising.

Maybe this method could be added with another name, like awaitAtMostOne, but we would like first to know the use cases for this methods. Could you please share yours?

@JasonMing
Copy link
Author

Hi @dkhalanskyjb! This issue seems has been obsoleted after kotlinx.coroutines 1.4.0 released at 27 Oct 2020.
If only focus on this issue, the reason I'd like to request awaitSingleOrNull() feature is, awaiting on a Mono which I don't care about its value but only status, single may provide better readability and semantic than first.
This await operation is common in bridging reactive api in coroutine context.

@dkhalanskyjb
Copy link
Collaborator

This issue being obsoleted will become obsoleted after kotlinx.coroutines 1.5.0, as we plan to remove awaitSingleOrNull :) #2628
That said, your use case should not be affected, as awaitSingleOrNull on Mono will still be present. So, this issue can be closed then?

@JasonMing
Copy link
Author

ok👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants