Welcome! Please see the About page for a little more info on how this works.

0 votes
in core.async by

Type hinting inside of go-loop or a go block with a loop in it loses the type hinting information. It appears that a channel must be read from in order for the data to be lost.

`
user=> (require ['clojure.core.async :as 'async])
nil
user=> (import 'java.util.Date)
java.util.Date
user=> (set! warn-on-reflection true)
true
user=> (let [a [(Date.) (Date.)] #_=> ch (async/chan)]
#=> (async/go-loop []
#
=> (when (async/<! ch)
#=> (println (.getDate ^Date (get a 0)))
#
=> (recur))))
Reflection warning, /tmp/form-init7283017118477479525.clj:3:3 - reference to field getDate on java.lang.Object can't be resolved.

object[clojure.core.async.impl.channels.ManyToManyChannel 0x2572eb4e "clojure.core.async.impl.channels.ManyToManyChannel@2572eb4e"]

user=> (let [a [(Date.) (Date.)] #_=> ch (async/chan)]
#=> (async/go-loop []
#
=> (when (async/<! ch)
#_=> (println (.getDate ^Date (get a 0))))))

object[clojure.core.async.impl.channels.ManyToManyChannel 0x12e8b6a3 "clojure.core.async.impl.channels.ManyToManyChannel@12e8b6a3"]

user=> (let [a [(Date.) (Date.)]]
#=> (async/go-loop []
#
=> (println (.getDate ^Date (get a 0)))
#=> (throw (Exception. "repl abort"))
#
=> (recur)))
12

object[clojure.core.async.impl.channels.ManyToManyChannel 0x1b48111e "clojure.core.async.impl.channels.ManyToManyChannel@1b48111e"]

Exception in thread "async-dispatch-1" java.lang.Error: java.lang.Exception: repl abort

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1155)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

Caused by: java.lang.Exception: repl abort

at user$eval1611$fn__1618$state_machine__6321__auto____1621$fn__1623$fn__1625.invoke(form-init7283017118477479525.clj:3)
at user$eval1611$fn__1618$state_machine__6321__auto____1621$fn__1623.invoke(form-init7283017118477479525.clj:2)
at user$eval1611$fn__1618$state_machine__6321__auto____1621.invoke(form-init7283017118477479525.clj:2)
at clojure.core.async.impl.ioc_macros$run_state_machine.invokeStatic(ioc_macros.clj:973)
at clojure.core.async.impl.ioc_macros$run_state_machine_wrapped.invokeStatic(ioc_macros.clj:975)
at user$eval1611$fn__1618.invoke(form-init7283017118477479525.clj:2)
at clojure.lang.AFn.run(AFn.java:22)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
... 2 more

`

1 Answer

0 votes
by
Reference: https://clojure.atlassian.net/browse/ASYNC-207 (reported by wickedshell)
...