I wonder where is the best place to call subscribeOn and observeOn methods? What module(s) should handle all threading related activities?
In this particular architecture, creating interfaces for getting a background thread (ThreadExecutor.java) to subscribeOn, and a handler thread (PostExecutionThread.java) to observeOn should be handled in the domain. This way, you can create implementations of these threads from application to application within the data module and presentation module respectively.
As far as I understand it, the data module handles the creation of background threads (see JobExecutor.java for an example). This provides a background thread that is theoretically independent from the Android framework. The UIThread, however, has to be Android dependent, so it is created in the presentation layer (see UiThread.java for an example).
If you would like to see how both ThreadExecutor and PostExecutionThread come together, check out the UseCase.java file. That is where both the subscribeOn and observeOn methods are called.
TL;DR the best place to handle your Observable, and call subscribeOn/observeOn is in the domain module, all you need to do here is create interfaces that promise to get threads at some point. Within the data module, you would implement a background thread of some sort. Then create a UI thread implementation within the presentation layer. These will all be passed into a UseCase in the domain layer.
I hope this helps.
Let me know if you have any other questions.
Seems reasonable for me. Thank you very much for a detailed answer, somehow i managed to miss this in code.
Most helpful comment
In this particular architecture, creating interfaces for getting a background thread (ThreadExecutor.java) to subscribeOn, and a handler thread (PostExecutionThread.java) to observeOn should be handled in the domain. This way, you can create implementations of these threads from application to application within the data module and presentation module respectively.
As far as I understand it, the data module handles the creation of background threads (see JobExecutor.java for an example). This provides a background thread that is theoretically independent from the Android framework. The UIThread, however, has to be Android dependent, so it is created in the presentation layer (see UiThread.java for an example).
If you would like to see how both ThreadExecutor and PostExecutionThread come together, check out the UseCase.java file. That is where both the subscribeOn and observeOn methods are called.
TL;DR the best place to handle your Observable, and call subscribeOn/observeOn is in the
domainmodule, all you need to do here is create interfaces that promise to get threads at some point. Within thedatamodule, you would implement a background thread of some sort. Then create a UI thread implementation within thepresentationlayer. These will all be passed into a UseCase in thedomainlayer.I hope this helps.
Let me know if you have any other questions.