5

I could never understand the difference between blockingSingle and blockingFirst on Observables in RxJava. Any help would be greatly appreciated.

Virendra
  • 115
  • 2
  • 10

1 Answers1

8

definitions from https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators

first() — block until the Observable emits an item, then return the first item 
emitted by the Observable

single( ) — if the Observable completes after emitting a single item, return 
that item, otherwise throw an exception

sounds like first() immediately returns upon emitting any item, and single() waits for the Observable to complete to return.

ehacinom
  • 8,070
  • 7
  • 43
  • 65
  • 1
    More precisely, `single` and `blockingSingle` expects the source to have one item. If it has more than one, they signal an exception instead and you don't get any items. – akarnokd Jan 16 '19 at 08:36