2

I’m trying to create an Observable from an iterator that is not thread safe. I’m creating the iterator using Observable.resource, and then creating an Observable around this iterator using Observable.fromIterator. I then use .executeWithModel(ExecutionModel.SynchronousExecution) which I thought would force the resulting observable to run on the same thread even with a Scheduler that manages multiple threads.

It turns out that this is not the case, as my observable fails sometimes if it is zipped with another observable for example, and I suspect that I may get other issues like this if I use a global, multi-threaded scheduler.

One thing that seems to work is to run this observable on a single-threaded scheduler, but this make me either share one for every execution of this observable or create a new one every time. Is there any better way to make sure that my observable always run on the thread it was started on?

WilQu
  • 7,131
  • 6
  • 30
  • 38

0 Answers0