Skip to content

Instantly share code, notes, and snippets.

@dmytrodanylyk
Last active October 10, 2017 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmytrodanylyk/34bdb2a619bac8444061e581037b8fcb to your computer and use it in GitHub Desktop.
Save dmytrodanylyk/34bdb2a619bac8444061e581037b8fcb to your computer and use it in GitHub Desktop.
class MainPresenter(private val view: MainView,
private val dataProvider: DataProviderAPI
private val uiContext: CoroutineContext = UI,
private val ioContext: CoroutineContext = CommonPool) {
private fun loadData() = launch(uiContext) { // use the provided uiContext (UI)
view.showLoading()
// use the provided ioContext (CommonPool)
val task = async(bgContext) { dataProvider.loadData("Task") }
val result = task.await()
view.showData(result)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment