How to inject extrenal CoroutineScope into repository In Multi Modular Application

77 Views Asked by At

My app architecture consists of multi module like app-core-feature. In Business layer, repository needs an external application or activity level CoroutineScope not to be cancelled while doing network - data suspend operation. How can I achive this by taking into consideration Repository cannot access to app module and feature module. Repository is like:

class ArticlesRepository(
    private val articlesDataSource: ArticlesDataSource,
    private val externalScope: CoroutineScope,
) {
    
    suspend fun bookmarkArticle(article: Article) {
        externalScope.launch { articlesDataSource.bookmarkArticle(article) }
            .join() 
    }
}

This is from best practice example

0

There are 0 best solutions below