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

CLOVIS

07/28/2019, 6:56 PM
Is there a ReceiveChannel equivalent where every coroutine waiting to receive does receive, instead of a single random one? The idea is that a single coroutine handles internally whether or not to download some objects from the internet (by delegating to a worker pool, then caching the result). Let's call it cacheManager. The outside program can send an ID to cacheManager over its ReceiveChannel. You can then listen on cacheManager's SendChannel to get the object back, but if multiple people query at the same time, nothing ensures you'll get your request's results...
d

Dominaezzz

07/28/2019, 8:14 PM
BroadcastChannel
?
It looks like you require a complex actor.
You don't need a channel to achieve this, a simple suspending request method should do.
👍 1
suspend fun CacheManager.getObject(key: String): Any
should be enough.
3 Views