Reputation: 465
The documentation says, that a Subject is a Observer and can subscribe to Observables, but I can't find a way to do it in code.
Thanks in advance!
Upvotes: 9
Views: 9964
Reputation: 957
Sample junit code:
@Test
public void shouldSubscribeToSubjectToObservable() throws InterruptedException {
Observable<Integer> observable = Observable.just(1, 2);
PublishSubject<Object> subject = PublishSubject.create();
subject.subscribe(o -> {
System.out.println("o = " + o);
});
observable.subscribe(subject);
Thread.sleep(1000);
}
Upvotes: 10