TestScheduler: Fix race condition in queue#3832
Conversation
|
TestScheduler is a synchronous Scheduler that has to run on a single thread and its main purpose is to force async operators to execute synchronously as well. Is there a reason you wanted this change? |
|
Humm. This is the crash I was trying to fix, looked like a race but perhaps I'm using the testscheduler incorrectly somehow. java.lang.NullPointerException |
|
My class under test is subscribing to the scheduler asynchronously, I guess you're saying TestScheduler wasn't designed to operate list this? Observable.interval(mPollTimeMinutes, TimeUnit.MINUTES, mScheduler) |
|
It won't work with regular schedulers, for example: Observable.interval(1, TimeUnit.MILLISECONDS) // <-- note: it uses the default computation() scheduler
.observeOn(testScheduler)
.subscribe();is prone to concurrency issues. If you use |
|
Thanks for helping - is this how it's intended to be used? Observable.interval(1, TimeUnit.MILLISECONDS, test ? testScheduler : Schedulers.computation()) |
|
Yes. |
|
Awesome, thanks. |
No description provided.