android / codelab-kotlin-coroutines

Kotlin Coroutines codelab
Apache License 2.0
552 stars 268 forks source link

11. Using coroutines in higher order functions #122

Open Digipom opened 3 years ago

Digipom commented 3 years ago

There seems to be an issue with launchDataLoad -- if more than one function uses that and they both execute concurrently, then it seems that the spinner might be prematurely set to false. For example:

1) Call launchDataLoad with two functions, A, and B. 2) They both set the spinner to true. 3) A finishes first. The spinner is now set to false, even though B is still running.

Even if it won't happen with the specific example code, since the codelab talks about creating functions like this to generalize to any data loading, it may be worth mentioning or showing a way to handle that using coroutines.