Skip to content

Instantly share code, notes, and snippets.

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 binaryroot/d304ad9b11387c1942f309fd63a16388 to your computer and use it in GitHub Desktop.
Save binaryroot/d304ad9b11387c1942f309fd63a16388 to your computer and use it in GitHub Desktop.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
launch(context = UI) {
val result = async { loadString() }.await()
Log.d("TAG",
"Post execution thread:"+Thread.currentThread().name)
textView.text = result
}
}
private suspend fun loadString() : String {
Log.d("TAG", "Execution thread: "+Thread.currentThread().name)
delay(1000L)
return "Some loaded string..."
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment