I'm looking for some kind of permanent continuatio...
# coroutines
p
I'm looking for some kind of permanent continuation. I have a function that at some point has to wait on a callback. So I could use suspendCoroutine and store the continuations in a queue. The callback could then then pop the queue items and call resume on each. However it would be more elegant to have some kind of lock object so suspending functions could lock on it and then all resume when the lock object gets unlocked. Is there something built in for that?
e
Have you taken a look at channels?
p
so like val channel = ConflatedBroadcastChannel<Boolean>()
then the callback calls channel.offer(myBool)
And the suspending function channel.openSubscription().first ?
Ah no it's RendezVouzChannel and the method is called
receive()
. Thanks for the hint!
d
If all you need is to wait for one callback result in many `launch`ed coroutines, you could just run it in
async {}
beforehand, and then launch them all and call
await
in each of them, they'll all suspend until async is finished.