Thursday 18 January 2018

Operator - Do




Do

register an action to take upon a variety of Observable lifecycle events





You can register callbacks that ReactiveX will call when certain events take place on an Observable, where those callbacks will be called independently from the normal set of notifications associated with an Observable cascade. There are a variety of operators that various ReactiveX implementations have designed to allow for this.


RxJava 2․x doAfterTerminate doOnComplete doOnDispose doOnEach doOnError doOnLifecycle doOnNext doOnSubscribe doOnTerminate onTerminateDetach


--------------------------------------------------------------------------------------------


       Observable.just("Hello").doOnNext(new Consumer<String>() {
                   @Override
                   public void accept(String s) throws Exception {
                       System.out.println("Consumer Test");
                   }
               })
                .doOnEach(new Observer<String>() {
                    @Override
                    public void onSubscribe(Disposable disposable) {

                    }

                    @Override
                    public void onNext(String s) {
                        System.out.println("Observer Test");
                    }

                    @Override
                    public void onError(Throwable throwable) {

                    }

                    @Override
                    public void onComplete() {

                    }
                })
               .doOnComplete(new Action() {
                   @Override
                   public void run() throws Exception {
                       System.out.println("Action Test");
                   }
               })

               .subscribe();


--------------------------------------------------------------------------------------------






































22

No comments:

Post a Comment

Calling method Sequencely

1. Execute multiple task sequencly (WAY-1) ------------------------------------------------------------------------------ import io.re...