android10 / Android-CleanArchitecture

This is a sample app that is part of a series of blog posts I have written about how to architect an android application using Uncle Bob's clean architecture approach.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use of Schedulers on UseCase

canemacchina opened this issue Β· comments

Hi,

I was reading your project and there's something regarding the use of Schedulers on UseCase that I don't well understand.

Note that I'm quite new to android programming so please forgive me if I say something terribly wrong! πŸ˜…

So, why the UseCase needs a ThreadExecutor for the "backend" computation and a Scheduler to execute the observer? Why not ask for the same type?

I mean, if the reason to ask for a ThreadExecutor is to be free to use whatever executor you want, why the same thing doesn't apply for observeOn? Why can't we ask again for another ThreadExecutor and simply call observeOn(Schedulers.from(executor))?
(Note: I understand that is very simple to refer to the main thread using Schedulers thanks to AndroidSchedulers.mainThread(). There isn't a so simple way to obtain the main ThreadExecutor on Android?)

And why we can't achieve the same result asking for two Schedulers?
I mean, if I want simply use Schedulers.io() as background scheduler, how can I pass it to the UseCase?
If the UseCase was asking for a Scheduler also for subscribeOn, I could pass Schedulers.io() or a custom scheduler (created with Scheduler.from(myThreadExecutor)) based on my need.

Thanks in advance!