-
-
Save recheej/387a0ea70552c0bff983b8028591f2cc to your computer and use it in GitHub Desktop.
Idiomatic way to perform non critical suspending work in a suspend function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Repository( | |
private val database: Database, | |
private val nonCriticalScope: CoroutineScope, | |
private val networkRepository: NetworkRepository | |
) { | |
suspend storeItem(item: Item) { | |
nonCriticalScope.launch { | |
// this is a sync operation. I don't really care if it fails. | |
networkRepository.updateDataOnNetwork(item) //suspension point | |
} | |
database.insert(item) //suspension point | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment