Fork me on GitHub
#core-async
<
2018-01-03
>
schmee02:01:40

would it be possible to make a version of alts! that takes an iterable of channels instead of a vector?

tbaldridge14:01:28

@schmee alts! really only calls nth on the collection you give it. So it could be an array or a seq, iterables would have to be converted to something that supports nth

tbaldridge14:01:44

this is because alts! requires random access to the collection, because it does some randomization of the data internally. alts! will attempt to operate on channels in a non-deterministic way in order to avoid starving some processes

schmee14:01:43

ahh, I see, maybe you can help me figure out a way to solve the issue I’m expecting

schmee14:01:42

I’m alting over a potentially large vector which is created from the keys of a concurrent hash map. I would like to avoid recreating the vector everytime an element is added or removed from the map since this will be happening a lot

schmee14:01:44

my idea was to maybe use the KeySet for the map somehow but since random access is required I see now why that won’t work

schmee14:01:50

any ideas on how to approach this problem?

tbaldridge16:01:45

@schmee optimizing this won't help a whole lot, since internally alts! will be putting these values into an array and doing other things with them

tbaldridge16:01:20

@schmee perhaps, invert the flow? Have all of these sources put into a common channel instead of trying to alt over a lot of channels?

schmee17:01:20

that might work, I’ll try it out!

schmee17:01:26

thanks for the help 🙂