Skip to content

Fixes SingleItemObservable to emit item only once #631

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

Merged
merged 1 commit into from
Jan 13, 2021

Conversation

gael-ft
Copy link
Contributor

@gael-ft gael-ft commented Jan 13, 2021

Hi MongoDB, @rozza,

I observed what seems to be a tiny bug.
It is about the SingleItemObservable class.
This class is called in SingleObservable.scala file

object SingleObservable {

  /**
   * Creates an SingleObservable from an item.
   *
   * Convenient for testing and or debugging.
   *
   * @param item the item to create an observable from
   * @tparam A the type of the SingleObservable
   * @return an Observable that emits the item
   */
  def apply[A](item: A): SingleObservable[A] = SingleItemObservable(item)
}

I figured it out when adding tests and mocking some DB calls, and returning SingleObservable(aTestValue), I always got an exception :

java.lang.IllegalStateException: SingleObservable.onNext cannot be called with multiple results.
	at org.mongodb.scala.ObservableImplicits$ToSingleObservablePublisher$$anon$1.check(ObservableImplicits.scala:125)
	at org.mongodb.scala.ObservableImplicits$ToSingleObservablePublisher$$anon$1.onNext(ObservableImplicits.scala:114)
        ...

As a quick solution I have to use Observable(aTestValue :: Nil).toSingle, which is aware of wether it was already completed. This PR is meant to add this into the SingleItemObservable class.

I did not create a JIRA ticket for this, as it is a very tiny issue, but I can if necessary.

Thanks !

@rozza rozza merged commit b2fde42 into mongodb:master Jan 13, 2021
@rozza
Copy link
Member

rozza commented Jan 13, 2021

Thanks @gael-ft

jfitzu pushed a commit to nextworld-tools/mongo-java-driver that referenced this pull request Mar 3, 2021
jfitzu added a commit to nextworld-tools/mongo-java-driver that referenced this pull request Mar 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants