Fork me on GitHub
#core-async
<
2018-11-12
>
markmarkmark00:11:28

does anyone else think it would be nice if an exception thrown in a async/thread thread returned the exception over the channel that it gives you?

markmarkmark00:11:30

that might not be the best way to do it but it seems like there must be a better way than just saying that you should set an UncaughtExceptionHandler

csm01:11:40

Check out https://github.com/fullcontact/full.async. It provides some nice utilities for core.async, including something like what you’re proposing (go-try)

markmarkmark02:11:15

that's not bad.

markmarkmark02:11:30

I guess it isn't too hard to just write a macro that wraps the thread body with a try catch

leonoel08:11:58

it's harder than it sounds and there's no easy answer to this question

leonoel08:11:20

for instance full.async doesn't properly handle all error cases in javascript (it catches only Error, and you can throw anything in js)

leonoel08:11:11

you can also legitimately ask the question, what happens if a transducer attached to a channel throws ?

leonoel08:11:56

so because there's no obvious answer, core.async basically assumes you program defensively everywhere, and just spits out a stacktrace if something goes wrong

abdullahibra08:11:32

core.async try to do the same thing as golang goroutines ?

markmarkmark12:11:12

well, for only the thread macro and for only jvm hosted clojure, it isn't too hard to just write a macro that wraps the body. though, for the general case I suppose there might be more corner cases. Since the thread macro creates the channel and passes it directly back I don't think there's any way for that channel to have a transducer on it.

markmarkmark12:11:10

of course, it would also be easy to just manually wrap your thread body in a try catch and not worry about the extra macro unless you were really trying to make it a widely used pattern.

mpenet12:11:30

it's 10 lines of code to build your own version of async/thread

leonoel12:11:47

yes, for that special case it's a valid approach

markmarkmark13:11:06

for reference, this message is what made me start thinking about this. Because (probably unintentionally) @noisesmith made it sound like you could deal with what caused your thread to die (presumably an exception) at the place where you're parked on the async/thread. but, if an async/thread throws you just get a nil on the parked channel and no indication of what happened.

markmarkmark13:11:23

You'll probably know what could have caused the thread to die since you might have written the code it runs anyway, but if the thread is running some kind of black box that expects you to be able to handle exceptions, it might be some annoying debugging before you realize what's happening.

noisesmith16:11:32

Oh, I'd confused the behaviors of future and thread there

markmarkmark16:11:07

ha, I immediately rushed to my repl because I was amazed it worked that way.