I have what appears to be a locals-clearing bug when using core.async thread
(let [close? (promise)
thread-ch (a/go-loop []
(when (not (realized? close?))
(try
(stuff))
(recur)))]
(closeable thread-ch (fn [thread-ch]
(deliver close? true)
(a/<!! thread-ch))))
this code works. Swapping the go-loop
for a/thread
reliably causes an NPE when attempting (realized? close?)
println debugging shows close? to be a promise in in the first iteration through the code, and nil
in the second
what version of clojure and core.async? a more minimal repeatable case would be great. I did the minimal to get that to compile with the core.async 0.4.500 and clojure 1.10.1 (basically just defining the free names) and it runs without errors here
Oh, sorry I misread, that is the passing case, thread is the failing case
Yep, fails here too
it would be useful to isolate it without core.async, because thread doesn't do any code transforms so any behavior you get there should be repeatable elsewhere
alright
oh, I know what it is
you are replacing go-loop with thread without adding in a loop form
ah
yep, that’s it
which doesn't error when compiling because the recur just hits the fn introduced by thread, but errors when running because it's a :once fn
(a/thread (loop []…)
works
thanks
should :once fns be allowed to recur?
the function is still being invoked a single time, but has an internal goto
to recur
it seems like they should not, but it seems like the kind of thing someone somewhere is depending on