Observable.interval(1, TimeUnit.MILLISECONDS, Schedulers.immediate()).limit(5000)
.subscribe(new Subscriber<Long>() {
@Override
public void onCompleted() {
System.out.println("------------------------");
}
@Override public void onError(Throwable e) {
System.out.println("error");
}
@Override public void onNext(Long aLong) {
System.out.println("=========== " + aLong + " ===========");
}
});
Only occurs at "Schedulers.immediate()"
version: 1.0.10 and 1.1.6
When you use the default scheduler (Schedulers.computation()) the observable emits on another thread. If your program exits just after the subscribe then the observable is not given a chance to run. Put in a long sleep just after the subscribe() call and you will see it working.
The immediate() scheduler is not safe for recursive scheduling on the current thread, use trampoline() instead.
Thanks for your suggest, it works
Most helpful comment
When you use the default scheduler (
Schedulers.computation()) the observable emits on another thread. If your program exits just after thesubscribethen the observable is not given a chance to run. Put in a long sleep just after thesubscribe()call and you will see it working.The
immediate()scheduler is not safe for recursive scheduling on the current thread, usetrampoline()instead.