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

David Glasser

03/03/2020, 7:23 PM
I'm looking for a coroutine equivalent of CountdownLatch (even just for the most basic n=1 case) where one coroutine can block until another coroutine says it can go. What am I looking for?
o

octylFractal

03/03/2020, 7:24 PM
for
n=1
, I think mutex is sufficient
there's also Semaphore but it doesn't work as a CoutdownLatch
d

David Glasser

03/03/2020, 7:26 PM
thanks, that sounds good.
esp since they can start pre-locked 🙂
o

octylFractal

03/03/2020, 7:41 PM
the trick with coroutines is implementing these sorts of concurrency classes is much easier 🙂
d

Dominaezzz

03/03/2020, 8:14 PM
I direct equivalent is a
CompletableDeferred
. Okay... Somewhat direct. If n =1.
d

David Glasser

03/03/2020, 9:34 PM
@octylFractal I dunno that MutableSet is thread-safe?
o

octylFractal

03/03/2020, 9:35 PM
well, I did say it was quick and dirty :P you can likely replace it with CopyOnWriteArraySet for little performance loss
e

Evan R.

03/05/2020, 1:33 PM
Personally I’d use a rendezvous channel to effectively “trigger” the listening coroutine from the controlling coroutine but that’s just my opinion 🙃
778 Views