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

Daniel Tam

06/17/2018, 12:59 PM
just out of curiosity.. are there plans to implement suspending semaphores like we currently have suspending mutexes? You can make a very basic one right now by sending/receiving from a channel with a finite capacity - but then there's also stuff like acquiring n semaphores, and optimizing by disabling fairness https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Semaphore.html
g

gildor

06/17/2018, 2:43 PM
Do you have some particular use case for suspending semaphore?
d

Daniel Tam

06/17/2018, 3:15 PM
I'm benchmarking an application right now which involves sending concurrent requests to a server and measuring throughput. However, the application doesn't enjoy having too many concurrent requests open. So I try to send x requests concurrently using coroutines and I want most of those coroutines to suspend until it can acquire 1 out of 500 "semaphores", giving it permission to open a request
v

Vsevolod Tolstopyatov [JB]

06/17/2018, 7:32 PM
We don’t have such plans, our priority is to add more high-level features now (typed actors, cold streams, proper exception handling etc.). For your case, probably something like batch actor will help:
Copy code
val actor = workerPool(parallelism = n) { myRequestSendingActor() }

actor.request() // <- may be processed in up to n threads
That’s in our roadmap 🙂
👍 1
3 Views