This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-07-28
Channels
- # admin-announcements (28)
- # beginners (30)
- # boot (6)
- # cljs-dev (48)
- # clojure (72)
- # clojure-android (8)
- # clojure-australia (1)
- # clojure-italy (9)
- # clojure-japan (12)
- # clojure-russia (21)
- # clojure-sg (1)
- # clojurescript (109)
- # core-async (11)
- # core-logic (17)
- # cursive (33)
- # datascript (1)
- # datomic (30)
- # dunaj (4)
- # editors (38)
- # events (1)
- # ldnclj (17)
- # off-topic (156)
- # om (2)
- # overtone (1)
- # re-frame (2)
- # reagent (63)
I need to take one value from each channel in a collection, but the ordering doesn’t matter. Each time I get a value from a channel, I want to remove that channel from the list I’m waiting on. Does anyone have a good example of this pattern?
I’ve done
(loop [chans mychans]
(let [[_ p] (async/alts!! chans)
new-chans (remove #(= p %) chans)]
(when (not-empty new-chans)
(recur new-chans))))
but it feels a little inelegant, and I need to guard against calling alts!! with an empty collection of chans
Is anyone using offer!
in production? Looks like it’s documented but hasn’t been shipped to Maven.
@danielcompton: I do the same. The O(n) remove is not nice but alts! needs a vector so a set doesn't work.
It’s O(n^2) overall
@danielcompton: not sure this will work but have you tried using mix
to combine the channels into one, and then when you read use unmix
to remove that channel from the mix?
That could work...