-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Deprecate awaitSingleOr*, specialize some await* functions for Mono and Maybe #2628
Conversation
message = "Deprecated without a replacement due to its name incorrectly conveying the behavior. " + | ||
"Please consider using awaitFirstOrDefault().", | ||
level = DeprecationLevel.WARNING | ||
) | ||
public suspend fun <T> Publisher<T>.awaitSingleOrDefault(default: T): T = awaitOne(Mode.SINGLE_OR_DEFAULT, default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two things regarding deprecation:
- It's worth adding
### Deprecation
section to KDoc with an explanation of why this function is deprecated and, if necessary, why there is no built-in replacement. The rest of KDoc can be removed, but not hard opinion here. - To simplify maintenance and user's view of deprecation timeline, we add a short note about it:
@Deprecated(
message = "Deprecated without a replacement due to its name incorrectly conveying the behavior. " +
"Please consider using awaitFirstOrDefault().",
level = DeprecationLevel.WARNING
) // Warning since 1.5, error in 1.6, hidden in 1.7
|
||
override fun onComplete() { | ||
if (!seenValue) | ||
cont.resume(null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] I'd suggest sticking to either one-liners or using explicit scoping with {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
Please address minor doc issues and it's good to go
*/ | ||
@Deprecated( | ||
message = "Mono produces at most one value, so the semantics of dropping the remaining elements are not useful. " + | ||
"Please use awaitSingle() instead.", | ||
level = DeprecationLevel.WARNING, | ||
replaceWith = ReplaceWith("this.awaitSingle()") | ||
) | ||
) // Warning since 1.5, error in 1.6, hidden in 1.7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It won't be hidden because this is added as a lint hint, otherwise, it wouldn't be added in the first place
* function immediately cancels its [Subscription] and resumes with [CancellationException]. | ||
* | ||
* @throws NoSuchElementException if the publisher does not emit any value | ||
* This function is deprecated in favor of [Mono.awaitSingle]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This phrasing implicitly implies that this function was non-deprecated prior to this version.
I suggest rephrasing it more explicitly, e.g.: "This is a deprecated lint function to improve user experience and guard against ambiguous Mono usages." and adding example to the end of KDoc:
Example of ambiguous usage:
\```
// The signature of the call suggests that one or zero values can be returned from 'findById', but 'awaitFirstOrNull' instead of 'awaitSingleOrNull' may trick the reader into believing that more than one value can be returned
myDbClient.findById(uniqueId).awaitFirstOrNull()
\```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
…nd Maybe (Kotlin#2628) * Deprecated `awaitSingleOr*` on arbitrary Publishers * Added specialized `awaitSingle` and `awaitSingleOrNull` methods on `Maybe<T>` and `Mono<T>` * Deprecated `Maybe<T>.await()` in favor of `Maybe<T>.awaitSingleOrNull()` * Added specializations of most of the `await*` methods for `Mono<T>` and deprecated them, as the only useful methods on `Mono<T>` are `awaitSingle` and `awaitSingleOrNull` * Reworded some documentation for `await*` methods Fixes Kotlin#2591 Fixes Kotlin#1587
This PR
awaitSingleOr*
on arbitrary PublishersawaitSingle
andawaitSingleOrNull
methods onMaybe<T>
andMono<T>
Maybe<T>.await()
in favor ofMaybe<T>.awaitSingleOrNull()
await*
methods forMono<T>
and deprecates them, as the only useful methods onMono<T>
areawaitSingle
andawaitSingleOrNull
await*
methodsFixes #2591
Fixes #1587