Im a bit confused about case. Why does this work:
(defn reader=>channel [^Reader rdr ch]
(loop []
(let [c (.read rdr)]
(if (= c -1)
(t/log! "reader-loop shutdown: received -1")
(do (a/>!! ch c)
(recur))))))
But this fails (-1 branch never gets hit and the -1s are spammed onto the channel)?
(defn reader=>channel [^Reader rdr ch]
(loop []
(let [c (.read rdr)]
(case c
-1 (t/log! "reader-loop shutdown: received -1")
(do (a/>!! ch c)
(recur))))))
both versions work in my repl, what's your environment ?
(defn reader=>out [^java.io.Reader rdr]
(loop []
(let [c (.read rdr)]
(case c
-1 (println "reader-loop shutdown: received -1")
(do (prn c)
(recur))))))
(reader=>out (java.io.StringReader. "abc"))
97
98
99
reader-loop shutdown: received -1Thank you for the sanity check! I should have tried it "atomically" like that myself. Can't reproduce the original error anymore, even though it persisted accross repl restarts. There must've been some stray form that got evaluated when loading the file. Time to develop a tidier workflow :o
> it persisted across repl restarts scary. I've had some stale compiled files trip me up in the past but it's been a while since I've encountered this kind of issue. A lot of those went away by adding "%s" to the target path in leiningen if that's what you're using. The good thing is that it's usually a bit easier in clojure to try thing "atomically" when weird things happen.
Oh, good to know that can happen. The thing I'm playing with blows up a lot - maybe because of JNI stuff going on under the hood - and I have to force kill the repl. Though I suspect human error in this particular case.