https://kotlinlang.org logo
#coroutines
Title
# coroutines
a

Alexander Vtyurin

06/26/2019, 8:03 PM
Is there a better way to implement suspending
while
loop instead of this?
Copy code
while (condition) {
   ...
   delay(1)
}
s

streetsofboston

06/26/2019, 8:06 PM
Hard to tell without knowing what the loop is for
a

Alexander Vtyurin

06/26/2019, 8:11 PM
I have blocking function
getFromQueue
that in loop tries to get something from a concurrent queue until there is something. If there is nothing it tries again. I've just figured out I can do a generator instead of
getFromQueue
.
s

streetsofboston

06/26/2019, 8:13 PM
Yup, then there is no need to call
delay(....)
or
yield()
.
a

Alexander Vtyurin

06/26/2019, 8:14 PM
Thank you.
d

Dico

06/27/2019, 12:55 AM
You can also use channel instead of queue
e

efemoney

06/27/2019, 2:50 AM
Yes a RENDEZVOUS
Channel
is somewhat analogous to your “blocking queue”
d

Dico

06/27/2019, 9:54 AM
It would be more like an array channel
a

Alexander Vtyurin

06/27/2019, 1:07 PM
You can also use channel instead of queue
Great stuff.
4 Views