Fork me on GitHub
#core-async
<
2018-04-26
>
danboykis14:04:34

@lxsameer why not pass the channel c to some-fn directly?

lxsameer14:04:26

@danboykis it's a PoC code the design isn't important to me, my main concern is that a piece of code which uses a value extracted from a channel and outside of a go block, does it actually runs on the main thread or not

danboykis14:04:35

(go (<! c)) would extract a value from the channel, but it will be in a new channel returned by the go block

danboykis14:04:35

i doubt you really want that... maybe you want (let [v (<!! c)] (some-fn v))

danboykis14:04:47

and yes some-fn would run on the main thread

danboykis14:04:44

in your example some-fn would be called on the main thread with an argument being a channel v

danboykis14:04:50

if you use <!! some-fn will also be called on the main thread but the argument v will be the value taken from channel c

lxsameer16:04:50

@danboykis yeah you're right, I forgot that go returns a channel itself

ajs21:04:37

I have a try/catch block inside a go block, and in the catch block, I put the exception onto an error channel, and when I read it from that channel, I just log it to the REPL. This works and catches exceptions, but I can't see a stacktrace. Any suggestions?

noisesmith21:04:52

why would you see a stacktrace? you mean the logging step isn't happening?

ajs21:04:09

it logs but it just says java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Keyword I'm sure the error is easy to track down if a I see a trace.

ajs21:04:29

the *e doesn't seem to work if the exception is thrown on another channel

noisesmith22:04:14

@ajs - that's just the message - why not print the stack trace? if you use pr-str clojure will make the whole stack trace part of the printed representation of the exception

noisesmith22:04:24

or prn instead of println

noisesmith22:04:38

right, *e is for the repl

ajs22:04:55

I am using print

noisesmith22:04:01

then use prn

noisesmith22:04:26

or, pr - since print is println without the newline, and pr is prn without the newline

ajs22:04:17

i shall try now

ajs22:04:13

that worked. why prn but not print worked to print the exception?

noisesmith22:04:08

println uses toString, which is defined by java.lang.Exception in java and does not include the stack trace, prn uses print-method and is defined in clojure code and does include the stack trace

noisesmith22:04:33

so the short version is - clojure does the convenient thing, java doesn't, use prn to get the clojure version

ajs22:04:42

very interesting indeed

noisesmith22:04:07

in general, you can use prn to get clojure's idea of how a thing should print, and println to get java's version

noisesmith22:04:16

(that's a vast oversimpliciation, there's more to it)

noisesmith22:04:44

the prn version is often "readable" so you could read the string and make an equivalent piece of data (doesn't apply to exceptions)