Skip to content

Instantly share code, notes, and snippets.

@omkar-tenkale
Created June 3, 2023 10:38
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 omkar-tenkale/9c34b1a0bfda126c64dedbe2a6d97f80 to your computer and use it in GitHub Desktop.
Save omkar-tenkale/9c34b1a0bfda126c64dedbe2a6d97f80 to your computer and use it in GitHub Desktop.
button.setOnClickListener{
launch(Dispatcher.Main) {
textView.text = "Downloading file" // Runs on main thread
suspendCoroutineUninterceptedOrReturn<Unit> { cont ->
thread {
downloader.download("http://example.com/file.txt") // Runs on Background thread
cont.resumeWith(Result.success(Unit))
}
COROUTINE_SUSPENDED
}
textView.text = "Download Complete" // CRASH! Runs on Background thread
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment