``` fun updateDetails() = GlobalScope.launch(<http...
# coroutines
d
Copy code
fun updateDetails() = GlobalScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
    // loop forever
    updateDetailsAsync()
    // wait until updateDetailsAsync is done
}

fun CoroutineScope.updateDetailsAsync() {
    does an REST API lookup
    writes into a database
}
s
Why doesnt a
while (true)
loop cut it?
d
That's what I thought about doing...but I wanted to know if there was a kotlin/coroutine way
more idomatic with using coroutines
I suppose this will do:
s
A key design feature of coroutines is that sequential stuff looks and acts the same as in "normal" kotlin
d
Copy code
do {
updateDetailsAsync()
delay(MINUTES.toMillis(1))
} while (true)
Thanks Johannes! 🙂
I suppose another way is for the
CoroutineScope.updateDetailsAsync()
to return a Job, then join on the job
s
Or just make it
suspend
?
d
great!
d
Perhaps
while(isActive)
is a bit better.
3
s
Why ?
d
It allows for cancellation if need be.
s
So does calling a
suspend
function no ?
d
Yes your code allows for cancellation as it is but you asked for idiomatic.
👍 1
d
ta! 🙂