google-developer-training / basic-android-kotlin-compose-training-race-tracker

Apache License 2.0
31 stars 30 forks source link

Android Basics: Introduction to Coroutines in Kotlin Playground #26

Open alghe-global opened 5 months ago

alghe-global commented 5 months ago
Add print statements to see what thread you are on by calling Thread.currentThread().name.

https://developer.android.com/codelabs/basic-android-kotlin-compose-coroutines-kotlin-playground?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-5-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-coroutines-kotlin-playground#4

code is not properly indented

should be

runBlocking {
        println("${Thread.currentThread().name} - runBlocking function")
        launch {
            println("${Thread.currentThread().name} - launch function")
            withContext(Dispatchers.Default) {
                println("${Thread.currentThread().name} - withContext function")
                delay(1000)
                println("10 results found.")
            }
            println("${Thread.currentThread().name} - end of launch function")
        }
        println("Loading...")
    }