I'm looking for a coroutine equivalent of Countdow...
# coroutines
d
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
for
n=1
, I think mutex is sufficient
there's also Semaphore but it doesn't work as a CoutdownLatch
d
thanks, that sounds good.
esp since they can start pre-locked 🙂
o
the trick with coroutines is implementing these sorts of concurrency classes is much easier 🙂
d
I direct equivalent is a
CompletableDeferred
. Okay... Somewhat direct. If n =1.
d
@octylFractal I dunno that MutableSet is thread-safe?
o
well, I did say it was quick and dirty :P you can likely replace it with CopyOnWriteArraySet for little performance loss
e
Personally I’d use a rendezvous channel to effectively “trigger” the listening coroutine from the controlling coroutine but that’s just my opinion 🙃
1391 Views