Can Publish Subject have multiple subscribers

Viewed 1694

I'm trying to subscribe following function, but functions's subscribe function doesn't receive any data, but error function does. I realized that if I create second subscriber inside of function it doesn't receive data too. I was able to add multiple subscriber to subject when using Rx-JS. Is it same for Rx-Java or is there different behavior, or am I doing something completely wrong?

public static PublishSubject<Boolean> doSomeWork() {
    final PublishSubject<Boolean> res = PublishSubject.create();
    doSomeOtherWork().subscribe(new Consumer<Boolean>() {
                @Override
                public void accept(@NonNull Boolean aBoolean) throws Exception {
                    res.onNext(true);
                }
            });

    res.subscribe(new Consumer<Boolean>() {
        @Override
        public void accept(@NonNull Boolean bool) throws Exception {
        //receives data
        }
    }, new Consumer<Throwable>() {
        @Override
        public void accept(@NonNull Throwable throwable) throws Exception {
            handleSomeStuff()
                    .subscribe(new Consumer<Boolean>() {
                        @Override
                        public void accept(@NonNull Boolean aBoolean) throws Exception {
                            res.onNext(aBoolean);
                        }
                    });
        }
    });
    return res;

}
1 Answers
Related