Tom Yuval
08/31/2022, 12:00 PMdelay(1)
in several places, to achieve just that: when any coroutine hits the delay(1)
its execution is suspended, allowing others to run (and complete or hitting delay(1)
themselves, allowing suspended coroutines to resume). And it generally seems to work. But it’s not elegant, and the delay itself, while not that noticeable, is not necessary.
Is there another way to do it? Something I can do at certain places in the code to allow a coroutine to suspend execution just in order to allow others to run until they complete or do the same?christophsturm
08/31/2022, 12:02 PMyield()
?Tom Yuval
08/31/2022, 12:31 PMyield()
, which seems to be what I was looking for.
Secondly, there seems to be some subtle difference in functionality in practice: I’ve noticed that when I was using delay(1)
garbage collection would sometimes take place before the coroutine resumed, and with yield()
it doesn’t seem to happen. Does someone know why that is, and advise on how to enable garbage collection to take place (it’s not normally a concern, I know, but for one of my use cases this is actually important)?