This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-10-29
Channels
- # aws (1)
- # beginners (65)
- # boot (400)
- # cider (19)
- # clara (2)
- # cljs-dev (29)
- # clojure (127)
- # clojure-chicago (2)
- # clojure-conj (1)
- # clojure-dev (12)
- # clojure-russia (156)
- # clojure-sg (6)
- # clojure-za (1)
- # clojurescript (193)
- # core-async (23)
- # datomic (91)
- # editors (4)
- # editors-rus (1)
- # events (1)
- # hoplon (3)
- # jobs (1)
- # ldnclj (6)
- # leiningen (3)
- # nginx (3)
- # off-topic (5)
- # om (93)
- # onyx (10)
- # re-frame (11)
- # spacemacs (1)
- # testing (2)
- # yada (5)
super happy about reduce respecting reduced - however I think the doc string should be more clear. Right now it ends with "ch must close before reduce produces a result." Which does not mention that it can also return a result before ch closing via reduced.
when a channel transducer produces a reduced value, the channel will be closed
not necessarily arguing that the docstring is clear enough, just not sure that you were aware of that
@alexmiller: Would Cognitect consider unifying the core.async namespaces? Using it in a cljc file is quite cumbersome (clojure.core.async, cljs.core.async, and cljs.core.async.macros).
Possibly, I need to talk about it with David and Rich
@alexmiller yeah I get that - what I am saying is that you can do like (def result-ch (ca/reduce (fn [x msg] (if (= msg :done) (reduced x) (conj x msg))) [] some-ch)) (ca/put! some-ch :a) (ca/put! some-ch :done) and some-ch will still be open, and result-ch will contain [:a]. The docstring makes it sound as if result-ch will not contain a result until the ch you pass in is closed. (at least that is how I read it)
In this, case, the final put! will both deliver the result to result-ch AND close some-ch. The close will most likely happen in the thread of the put! while the delivery will happen asynchronously in a thread from the pool, so it's actually undefined which happens first. I think it would be clearer though if the docstring explicitly mentioned reduced, I'll ask Rich about it.
I have been studying the pub/sub interface from core.async and I have an issue I have been struggling with I would like to have some discussion over.
If I want to close a topic as the publisher it appears I have no way to close the channels that are subscribed to that topic.
But from the other direction I only have the option of closing down the entire system by closing the publication channel. I have no way of closing just a particular topic down such that the clients of that topic will have their channels closed. This means that if a client does a go-loop in the normal way which simply doesn't recur if the channel is closed those go loops will now be orphaned.
I can work around this any number of ways and a poison pill would work. I could wrap the client channel with an intermediary that listens for nil or the poison pill and closes its wrapped channel. The external interface wouldn't change at all. So it is certainly a problem you can work around. It is just sort of an odd design given that closing channels and closing a topic seem to be analogous.
@alexmiller: to be as clear as I can here is a gist demonstrating that the ch you are reducing on is not explicitly closed by calling reduced from within the fn https://gist.github.com/shaunxcode/4f49eb4184fffc250742 (I am not saying this is right or wrong, just wondering if doc string is correct and behavior is wrong or vice versa - personally I think it is operating correctly as is and I can see use cases for wanting such behavior)
ah, I've totally been thinking about channel transducers not a/reduce this whole time
sorry, brain malfunction
if you want to file a ticket for this, I'll get to it eventually
@domkm: vote on http://dev.clojure.org/jira/browse/ASYNC-142, http://dev.clojure.org/jira/browse/ASYNC-141 and http://dev.clojure.org/jira/browse/ASYNC-119
Thanks @danielcompton. Will do.