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

asad.awadia

12/10/2020, 12:09 AM
what is the best way to simulate an arrayblockingqueue/channel ? MutableSharedFlow? I want to have a place to put items in such that only 1 of my 64 coroutines receive them - simple use case - items come in via a blocking http server [i.e. will need runBlocking to call any suspend methods] - I want to add it to the queue and have the coroutines in the background fetch them in chunks if possible
z

Zach Klippenstein (he/him) [MOD]

12/10/2020, 12:24 AM
That sounds like a use case for an actual channel.
a

asad.awadia

12/10/2020, 12:28 AM
Correct - I want to use a regular channel - but i keep reading flow preferred over channels
i

Ian Lake

12/10/2020, 12:29 AM
See Roman's recent post and the use case for channels as the mechanism for 'delivered only once': https://elizarov.medium.com/shared-flows-broadcast-channels-899b675e805c#49e3
☝️ 1
receiveAsFlow()
keeps the consuming side still using the flow APIs
z

Zach Klippenstein (he/him) [MOD]

12/10/2020, 12:30 AM
If you’re implementing a worker pool like it sounds like you are, there’s probably no need to have Flow involved at all
a

asad.awadia

12/10/2020, 12:31 AM
perf thanks!
5 Views