0

I'm developing a quite old application and need to handle between new rx way and old legacy threads. I started using repository pattern where all is emitted in Observables. And now I wanted to use my new repositories in old code. In RxJava it is quite simple, becuase I can use blockingGet() and my custom thread is waiting until something is produced or observable completes. I found that there is something like RxBlocking, but:

  • One thing is that there is mentioned in documentation that it is developed for testing only and should not be used in production.
  • I'm getting many crashes with EXC_BAD_ACCESS somewhere inside the .first() method.

Can you provide me some ideas how to handle the problem?

michalp
  • 83
  • 5
  • I think it would help if you gave a specific example. – Daniel T. May 30 '23 at 20:50
  • It's hard to give a specific example, because this problem occurs in random places. When I'm saving context, or when I'm trying to change a property of my core data object. – michalp May 31 '23 at 06:47
  • Using RxBlocking like this feels _very_ wrong to me; however, without more specifics there's not much that can be said. – Daniel T. Jun 02 '23 at 10:47

1 Answers1

0

I think, I found what was causing EXC_BAD_ACCESS. My operations were splitted between separated observables (ex I fetched data in one toBlocking().first() then I've modified the data and I saved them in the next one toBlocking().first(). When I merged everything in to one big observable combining my operation with .map() or flatMap() then everything started working properly.

I thought, that persistntContainer.newBackgroundContext() uses always the same thread, but when I checked that I noticed, that different threads are used for the perform() method.

michalp
  • 83
  • 5
  • That makes sense. RxBlocking is designed for testing. You wouldn't want independent tests to interfere with each other. – Daniel T. Jun 02 '23 at 10:49