This section explains the BlockingObservable subclass. A Blocking Observable extends the ordinary Observable class by providing a set of operators on the items emitted by the Observable that block.

To transform an Observable into a BlockingObservable, use the Observable.toBlocking( ) method or the BlockingObservable.from( ) method.

  • forEach( ) — invoke a function on each item emitted by the Observable; block until the Observable completes
  • first( ) — block until the Observable emits an item, then return the first item emitted by the Observable
  • firstOrDefault( ) — block until the Observable emits an item or completes, then return the first item emitted by the Observable or a default item if the Observable did not emit an item
  • last( ) — block until the Observable completes, then return the last item emitted by the Observable
  • lastOrDefault( ) — block until the Observable completes, then return the last item emitted by the Observable or a default item if there is no last item
  • mostRecent( ) — returns an iterable that always returns the item most recently emitted by the Observable
  • next( ) — returns an iterable that blocks until the Observable emits another item, then returns that item
  • latest( ) — returns an iterable that blocks until or unless the Observable emits an item that has not been returned by the iterable, then returns that item
  • single( ) — if the Observable completes after emitting a single item, return that item, otherwise throw an exception
  • singleOrDefault( ) — if the Observable completes after emitting a single item, return that item, otherwise return a default item
  • toFuture( ) — convert the Observable into a Future
  • toIterable( ) — convert the sequence emitted by the Observable into an Iterable
  • getIterator( ) — convert the sequence emitted by the Observable into an Iterator

This documentation accompanies its explanations with a modified form of "marble diagrams." Here is how these marble diagrams represent Blocking Observables:

see also:

Appendix: similar blocking and non-blocking operators

operatorresult when it acts onequivalent in Rx.NET
Observable that emits multiple itemsObservable that emits one itemObservable that emits no items
Observable.firstthe first itemthe single itemNoSuchElementfirstAsync
BlockingObservable.firstthe first itemthe single itemNoSuchElementfirst
Observable.firstOrDefaultthe first itemthe single itemthe default itemfirstOrDefaultAsync
BlockingObservable.firstOrDefaultthe first itemthe single itemthe default itemfirstOrDefault
Observable.lastthe last itemthe single itemNoSuchElementlastAsync
BlockingObservable.lastthe last itemthe single itemNoSuchElementlast
Observable.lastOrDefaultthe last itemthe single itemthe default itemlastOrDefaultAsync
BlockingObservable.lastOrDefaultthe last itemthe single itemthe default itemlastOrDefault
Observable.singleIllegal Argumentthe single itemNoSuchElementsingleAsync
BlockingObservable.singleIllegal Argumentthe single itemNoSuchElementsingle
Observable.singleOrDefaultIllegal Argumentthe single itemthe default itemsingleOrDefaultAsync
BlockingObservable.singleOrDefaultIllegal Argumentthe single itemthe default itemsingleOrDefault