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
elizarov
03/09/2018, 9:43 AM
Have you taken a look at channels?
p
Paul Woitaschek
03/09/2018, 9:55 AM
so like val channel = ConflatedBroadcastChannel<Boolean>()
Paul Woitaschek
03/09/2018, 9:55 AM
then the callback calls channel.offer(myBool)
Paul Woitaschek
03/09/2018, 9:56 AM
And the suspending function channel.openSubscription().first ?
Paul Woitaschek
03/09/2018, 10:07 AM
Ah no it's RendezVouzChannel and the method is called
receive()
. Thanks for the hint!
d
dave08
03/10/2018, 8:28 PM
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.