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

awaitSingleOrNull returns not nullable value #2591

Closed
Lewik opened this issue Mar 18, 2021 · 1 comment
Closed

awaitSingleOrNull returns not nullable value #2591

Lewik opened this issue Mar 18, 2021 · 1 comment

Comments

@Lewik
Copy link

Lewik commented Mar 18, 2021

public suspend fun <T> Publisher<T>.awaitSingleOrNull(): T = awaitOne(Mode.SINGLE_OR_DEFAULT)

awaitSingleOrNull returns not nullable value and

@throws NoSuchElementException if publisher does not emit any value

Also, behaviour differs from the std function:

@throws IllegalArgumentException if publisher emits more than one value

/**
 * Returns single element, or `null` if the list is empty or has more than one element.
 */
public fun <T> List<T>.singleOrNull()
@qwwdfsad
Copy link
Member

qwwdfsad commented Apr 6, 2021

Note that we also fixed the corresponding Flow operator for the same reason: #2289

pablobaxter pushed a commit to pablobaxter/kotlinx.coroutines that referenced this issue Sep 14, 2022
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants