Skip to content

Instantly share code, notes, and snippets.

@CDRussell
Last active March 12, 2020 01:47
Show Gist options
  • Save CDRussell/a823afd7233fe7e1897a2df6e90acde7 to your computer and use it in GitHub Desktop.
Save CDRussell/a823afd7233fe7e1897a2df6e90acde7 to your computer and use it in GitHub Desktop.
Coroutines
class TabSwitcherActivity : CoroutineScope by MainScope() {
fun onTabDeleted(tab: TabEntity) {
launch { viewModel.onTabDeleted(tab) }
}
}
class TabSwitcherViewModel {
suspend fun onTabDeleted(tab: TabEntity) {
tabRepository.delete(tab)
}
}
class TabRepository {
suspend fun delete(tab: TabEntity) {
deleteOldPreviewImages(tab.tabId)
tabsDao.deleteTabAndUpdateSelection(tab)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment