This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-10-22
Channels
- # admin-announcements (29)
- # aws (2)
- # beginners (25)
- # boot (110)
- # business (15)
- # cider (39)
- # cljs-dev (3)
- # clojure (90)
- # clojure-czech (28)
- # clojure-hamburg (1)
- # clojure-japan (24)
- # clojure-poland (149)
- # clojure-russia (46)
- # clojure-sg (9)
- # clojure-uk (6)
- # clojure-ukraine (1)
- # clojurescript (105)
- # core-async (37)
- # cursive (9)
- # dato (7)
- # datomic (6)
- # emacs (10)
- # events (1)
- # hoplon (22)
- # jobs (4)
- # ldnclj (38)
- # leiningen (4)
- # off-topic (17)
- # om (173)
- # onyx (134)
- # re-frame (46)
- # reagent (35)
well Rich almost always talks about channels as conveyer belts
Example: "the channel conveys a single value, an integer". Or "the channel conveys a series of maps."
I think take is complementary to put though
Yep, but most documentation I see stumbles on this, or uses the term "contains" which is not very accurate.
Hello hello! Question about handling exceptions in a channel. I have some code that looks like this:
(defn get-something [id]
(when-not (some #{id} permitted-ids)
(throw (Exception. "my exception message")))
(go
;; do some async stuff and return a channel with a result
))
(go (->> ids
(map get-something)
(async/merge)
(async/into #{})
(<!)))
The problem is that when exception is thrown inside the go block, it's being eaten, the channel is closed, and the process hangs because there's async/merge
waiting. Does anyone have any suggestions on how to properly handle situation like this?have you tried... catching the exception? :)
i’d like to throw it
Tim Baldridge has demo'ed a variant of the go block that catches and rethrows over a channel (I don't remember all the details)
gonna google it, thanks!
I'm pretty sure it's in his screencast series but is probably available in one of his repos somewhere
pinging @tbaldridge - link? :)
annapawlicka: i've found exceptions much less useful in an async context. An approach I've used it to turn the error directly into a map, close to the source
i think it might be here https://github.com/halgari/clojure-tutorial-source/blob/e01532e7249979f6104a231296a9144ad7dc8e32/src/core_async_tutorials/async_episode8.clj
Also, that thing you just linked http://swannodette.github.io/2013/08/31/asynchronous-error-handling/
Ah yes, I’ve been reading that post too
and this http://martintrojer.github.io/clojure/2014/03/09/working-with-coreasync-exceptions-in-go-blocks/
exceptions are fundamentally a way to handle problems across call stacks (which are broken apart into many ephemeral threads in an async architecture)
(which is also why debugging async stuff is annoying :)
Ok, I’m just going to log an error and move on, seems like the simplest and clearest thing to do.
But it’s good to find out how other folks are handling exceptions
you can also configure the default uncaught exception handler to log somewhere and that would handle this generically. not sure that's a great long-term strategy, but might be useful.
Interesting.. probably not the best solution for this scenario, but I didn’t know I could change the handler
you can also do it on a per-thread basis but there is not really any way to get to the 42+ threads under go blocks
I've had some success with the pattern of conveying either [exception] or [nil value], i.e.
(let [[exception result] (<! chan)]
(if exception ...
This is pretty close to how Node.js handles exceptions and the like, and is quite palatable using array deconstruction.
There can certainly be an issue where use of core.async, especially go macro, can result in an exception in a thread, and none of your code is in the stack trace!
i've been using the either-t<channel> monad transformer from cats in all my async cljs code... it makes for some very clean async error handling
@mccraigmccraig: can you share that?
@danielcompton: there used to be an example on the cats doc site, but now it's all about the nifty applicative-do syntax http://funcool.github.io/cats/latest/#channel ... i'll see if i can put an example together tomorrow