Home > Back-end >  Can you use both Kotlin Coroutines and RxJava in the same project, at the same time?
Can you use both Kotlin Coroutines and RxJava in the same project, at the same time?

Time:09-29

So I am hopping a project that uses RxJava A LOT. There split into modules, so it's like different entities inside the project. I'm looking to build a new module and I want to base it on Kotlin Coroutines. I feel like it shouldn't be an issue, but I'm asking anyways. Can you still use Both Kotlin Coroutines and RxJava under the same project? Thanks.

CodePudding user response:

A closer comparison to RxJava would be a library like Flow. Generally you want to use one or the other, there's only two reasons why you'd want to use both:

  1. You're transitioning from one to the other, but don't want to/too much effort to do it all at once.
  2. You're using one of them and a library you use requires the other.

But yes you can use them together, and bridging from one to the other isn't difficult.

CodePudding user response:

Short answer: Yes, you can.

If you're thinking of using Rx Java for mere treading then stop, and go with coroutines. If you want to use Rx Java for things such as event bus, object manipulation (Filter, Map etc etc), message passing and stuff (That RX java is generally made for) then go for it. Using Rx Java just for multithreading is an overkill.

  • Related