ursus
03/14/2025, 7:00 PMcoroutineScope {
launch {
while (isActive) { <--------
}
}
...
}
coroutineScope {
launch {
while (true) { <---------
}
}
...
}
When I want to do something while the coroutine is not cancelled - should I use isActive
or true
? Both seem to workYoussef Shoaib [MOD]
03/14/2025, 7:02 PMisActive
is probably safer.ursus
03/14/2025, 7:03 PMstreetsofboston
03/14/2025, 7:09 PMursus
03/14/2025, 7:10 PMJoffrey
03/14/2025, 8:11 PMisActive
check because you usually call suspend functions inside the loop. If you don't, the correct fix is probably to add some yield()
calls (or otherwise introduce suspension) rather than to change the conditionkevin.cianfarini
03/15/2025, 3:28 PMursus
03/15/2025, 3:42 PMwhile(isActive)
is the better practise it seemsJoffrey
03/15/2025, 5:17 PMJoffrey
03/15/2025, 5:17 PMyield()
. So you don't need isActive
checksstreetsofboston
03/15/2025, 7:30 PM