I'm new to RX and i don't know how the schedulers work. below is some code that never run onComplete
. but if i put a while(true)
loop at the end it works correctly. it seams the app will exit before running new thread
.
why is this happening? and how to fix this issue?
Subscriber<String> subscriber = new Subscriber<String>() {
@Override
public void onCompleted() {
System.out.println("done");
}
@Override
public void onError(Throwable throwable) {
}
@Override
public void onNext(String o) {
System.out.println(o);
}
};
Observable.from(new String[]{"1", "2", "3","4"}).
subscribeOn(Schedulers.immediate())
.observeOn(Schedulers.newThread())
.subscribe(subscriber);