Fork me on GitHub
#core-async
<
2023-03-22
>
stopa13:03:50

Hey team, noob question. I am using core-async, and wanted to propagate errors. The solution I've found so far is using <? and go-try The issue though, is that is kid of "colors" every function I use over a channel. For example:

(defn uh-oh-go-try
  []
  (go-try
    (throw (Exception. "uh-oh"))))

(<?? (a/into [] (a/merge [(uh-oh-go-try) (uh-oh-go-try)])))
;; will not throw
I could make wrappers, like into?, which checks for exceptions, but I wonder if there's a better way.

Ben Sless18:03:03

You need a "every" and "some", then every before the merge

👍 2
Ben Sless18:03:55

But you're stuck in a monad

Ben Sless18:03:35

You need monadic combinators

Ben Sless18:03:05

every, some and bind, I think are sufficient

Ben Sless18:03:22

you have the same issue if you work with anomalies

stopa12:03:50

Gotcha, thanks Ben! Exciting in a way -- feels like research

stopa15:04:26

Hey @UK0810AQ2, have you written every and some in the context of core-async by any chance? I'd be curious to take a peak at an example

Ben Sless16:04:08

Don't think I have, but those combinators aren't complicated

👍 2
Ben Sless18:04:48

Basically, some is alts!, every is merge with a little fix that lets you reorder results