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

Apache License 2.0
32 stars 35 forks source link

Android Basics: Introduction to Coroutines in Kotlin Playground #40

Open franklihs opened 3 months ago

franklihs commented 3 months ago

Hi,

I have a question about the Cancellation in Kotlin coroutines in the codelab for Android Basics. In the following link: 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#3

I have seen that in the step 2 of the Cancellation it says that when using the temperature.cancel() it will not show the temperature value because it was cancelled, however I can see that if the ${temperature.await() is not removed I get the following error:

image

Testing the code here I can see that if I just remove the ${temperature.await() from the code (without adding the temperature.cancel()) I get the same result as in the step 3.

My question is, what is the usability of the cancellation if it doesn't work without completelly removing the return of the function?

Thank you very much in advance for your time!