Android-cleanarchitecture: Where is the best place to call subscribeOn and observeOn methods?

Created on 29 Jun 2016  路  2Comments  路  Source: android10/Android-CleanArchitecture

I wonder where is the best place to call subscribeOn and observeOn methods? What module(s) should handle all threading related activities?

discussion question

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 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.

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rshah picture rshah  路  6Comments

misrakli picture misrakli  路  5Comments

fabius-bile picture fabius-bile  路  5Comments

Cook1 picture Cook1  路  4Comments

connexion2000 picture connexion2000  路  3Comments