These are chat archives for ReactiveX/RxJava

21st
Aug 2016
Eugene
@Hronom
Aug 21 2016 11:27

Hello guys, here is the simple code:

public class App {
    public static void main(String[] args) {
        PublishSubject<Integer> subject = PublishSubject.create();
        Observable<Integer> observable = subject.observeOn(Schedulers.computation());
        subject.onNext(1);
        observable.subscribe(App::ppp);
        System.out.println("on 2");
        subject.onNext(2);
        System.out.println("on 3");
        subject.onNext(3);
        System.out.println("on 4");
        subject.onNext(4);
        System.out.println("Complete");
        subject.onCompleted();
        // I need here wait until all ppp completes execution ?
    }

    private static void ppp(Integer ggg) {
        System.out.println(ggg);
        try {
            Thread.sleep(TimeUnit.SECONDS.toMillis(3));
        } catch (InterruptedException e) {
            e.printStackTrace();
            System.out.println("End " + e);
        }
        System.out.println("End " + ggg);
    }
}

So the question is what I need to put in the end of main to meet my requirements: wait until all ppp completes execution ? What is the right way in RxJava ?