RxJava - Completable Observable

RxJava - Completable Observable

Completable observable is only concerned about two things, if some action is executed or an error is encountered

 

Structure

public interface CompletableObserver {
    void onSubscribe(@NonNull Disposable d);

    void onComplete();

    void onError(@NonNull Throwable e);
}

 

Here only 2 events, onComplete and onError. This is useful for cases wherein we are only interested if something has executed properly ignoring output 

Completable can be converted to an observable using toObservable

Example

Completable.complete().subscribeWith(new CompletableObserver() {
         @Override
         public void onError(Throwable e) { 
            e.printStackTrace();
         }
         
         @Override
         public void onComplete() {
            System.out.println("Done!");
         }

            @Override
            public void onSubscribe(Disposable dspsbl) {
               
            }
      }); 

 

Output

Done