Can I interrupt an โevaluationโ, resulting from code like this:
(go
(while true
(println "hello")
(Thread/sleep 1000)))
I don't think so, it's in another thread now.
@pez there is no way to interrupt that no. it would also occupy an entire thread from the thread pool so this must be avoided at all cost ๐
I wonder if you can poke at that thread pool,
its a var in some namespace
How about if it is in ClojureScript? Iโm just curious.
CLJS doesn't have Thread/sleep?
No, but it has similar constructs, no? So you can evaluate something and get โdoneโ back and it would keep running.
but no you can't interrupt an infinite loop in JS. the browser will kill it eventually together with your page though ๐
no, you can't block in JS
There's no sleep function at least
if you just keep doing work nothing else will ever happen and your browser/node will lock up
There are blocking functions (e.g. Nodejs)
ok yes. there are ways to block, but it is a terrible idea to do that ๐
its ok if that is the only thing your program is supposed to be doing anyways
So in a ClojureScript REPL, using nREPL, is it possible to interrupt this?
((fn foo []
(println "hello")
(js/setTimeout foo 1000)))
no
Or does that fall under this? > no you canโt interrupt an infinite loop in JS
well it will have returned a number
you can use that number to call (js/clearTimeout num)
Yeah, but thatโs cheating. ๐
but that only works if you hit it before the first repeat ๐
but no that will forever keep doing its thing. no way to stop it. at least it will allow the browser to do other stuff while waiting for the timeout ๐
Indeed. It keeps printing here.
you can override what setTimeout
does but that gets into really messy territory ๐
At least in a browser app I can reload the page.
Iโm asking this because weโre implementing the interrupt op in Calva.
Seems like there'd be some value in a debugging api provided by browsers that had these registries available.
interrupt doesn't even work reliably in clojure/JVM
And we can now stop trying to figure out how these constructs would be interrupted. ๐