https://kotlinlang.org logo
Title
a

Aaron Todd

11/17/2020, 7:50 PM
if I have a background/worker coroutine that is processing tasks like so
1 suspend fun processTasks(chan: ReceiveChannel<MyTask>) {
2    for(task in chan) {
3        doWork() // non-suspend function
4    }
5 }
is it correct to say that on Line 3 once the coroutine is running on a thread it will not suspend again and potentially switch threads until the next call to
chan.receive()
on line 2? More generically the only time a coroutine has a chance to suspend is at a suspension point which is defined by a
suspend
function call? (i.e. no instruction level suspension possible)
z

Zach Klippenstein (he/him) [MOD]

11/17/2020, 8:06 PM
yep
a

Aaron Todd

11/17/2020, 8:59 PM
thanks, that was my understanding but sometimes you have to do a double check