https://kotlinlang.org logo
Title
w

WukongRework.exe

01/12/2021, 11:02 PM
I remember from somewhere that putting a loop inside of a coroutine is a pretty bad idea but I cant remember why. Could someone please explain why?
z

Zach Klippenstein (he/him) [MOD]

01/12/2021, 11:04 PM
In general, that’s not a bad idea. I’ve written and seen lots of coroutines with loops.
w

WukongRework.exe

01/12/2021, 11:12 PM
so in theory, if each coroutine launched inside of a loop that doesn't edit some global / shared state and are completely independent of each other then it shouldnt be a problem?
g

gildor

01/12/2021, 11:48 PM
If you have an infinite loop in a coroutine, and this loop doesn't have suspend functions inside of it, it will block current thread (because it will not allow other code to run on this thread), but it's a programming error rather than some issue with loops in coroutines
w

WukongRework.exe

01/12/2021, 11:49 PM
ah I see
b

bohsen

01/22/2021, 10:38 AM
A bit late to the show, but there's an excellent thread about it here: https://kotlinlang.slack.com/archives/C1CFAFJSK/p1608417755332100