https://kotlinlang.org logo
Title
j

jw

11/22/2018, 2:36 AM
It's doing other enqueued work
r

Ruckus

11/22/2018, 3:51 AM
What about when there isn't any enqueued work (such as a single
delay
)? Does it just do a busy loop? For example, if I do
suspend fun main() {
    delay(10_000L)
}
will it just eat the CPU for 10 seconds, or does it
wait
and
notify
the thread?
j

jw

11/22/2018, 4:17 AM
that's an implementation detail. i suspect it parks the thread and wakes it up if any new work is scheduled. Or perhaps if the gap is small enough it does a busy wait or calls
Thread.onSpinWait
👍 2
e

elizarov

11/22/2018, 7:31 AM
r

Ruckus

11/22/2018, 7:41 AM
I'm not entirely sure what parking is. It seems I have much to learn about coroutines.
e

elizarov

11/22/2018, 7:42 AM
Parking has nothing to do with coroutines. It is just a low level mechanism that “suspends a thread” in OS. You don’t have to know about it if you are using coroutines.
r

Ruckus

11/22/2018, 7:46 AM
Ah, that makes much more sense. Thanks!
l

louiscad

11/22/2018, 9:54 AM