Question

I was wondering if there is a convenient method to check if an observable has been completed. For instance I have a test

test("An observable that tracks another observable is completed")
{
      val sub = PublishSubject[Boolean](false)
      val newOb = sub recovered // This methods returns an Observable[Try[T]] 


      val res = scala.collection.mutable.ListBuffer[Try[Boolean]]()
      val cr = newOb subscribe( v => res += v, t => assert( false, "There shouldn't be an exception" ), () => println("Stream Completed") )
      sub.onNext(true)
      sub.onNext(false)
      sub.onNext(true)
      sub.onCompleted
      assert( res.toList === List(Success(true), Success(false), Success(true) ))
      newOb.isEmpty subscribe { v => assert( v == true, "Stream should be completed" ) }
  }

The recovered method returns an Observable[Try[T]] and is an extension to the standard Observable. I want to check that the Observable[Try[T]] is completed when the source Observable is completed.

So I wrote a test with a Subject to which I Publish a few values and then eventually complete. Is there a simple way I can check to see that newOb is also completed? There is no method like isCompleted in Observable.

Was it helpful?

Solution

This is the essence of the pattern Observer, when there is a call onCompleted, the appropriate handler is triggered, and only it can be understood that the Observer completed. But I have heard that if the Observer has been completed and it is attached to the handler, it works immediately, but I think it has already been implemented at a lower level where asJavaObserver.

That link may help: Netflix RxJava

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top