nrepl

https://github.com/nrepl/nrepl || https://nrepl.org
pez 2019-10-26T16:23:48.124600Z

Can I interrupt an โ€œevaluationโ€, resulting from code like this:

(go
    (while true
      (println "hello")
      (Thread/sleep 1000)))

dominicm 2019-10-26T18:30:35.124900Z

I don't think so, it's in another thread now.

thheller 2019-10-26T19:01:01.126600Z

@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 ๐Ÿ˜›

dominicm 2019-10-26T19:03:42.127100Z

I wonder if you can poke at that thread pool,

thheller 2019-10-26T19:05:13.127400Z

its a var in some namespace

pez 2019-10-26T19:05:50.128400Z

How about if it is in ClojureScript? Iโ€™m just curious.

thheller 2019-10-26T19:06:07.128700Z

CLJS doesn't have Thread/sleep?

pez 2019-10-26T19:06:49.129800Z

No, but it has similar constructs, no? So you can evaluate something and get โ€œdoneโ€ back and it would keep running.

thheller 2019-10-26T19:06:59.130100Z

but no you can't interrupt an infinite loop in JS. the browser will kill it eventually together with your page though ๐Ÿ˜‰

thheller 2019-10-26T19:07:19.130500Z

no, you can't block in JS

dominicm 2019-10-26T19:07:50.131500Z

There's no sleep function at least

thheller 2019-10-26T19:07:52.131600Z

if you just keep doing work nothing else will ever happen and your browser/node will lock up

dominicm 2019-10-26T19:08:10.132200Z

There are blocking functions (e.g. Nodejs)

thheller 2019-10-26T19:10:46.133400Z

ok yes. there are ways to block, but it is a terrible idea to do that ๐Ÿ˜›

thheller 2019-10-26T19:11:16.133900Z

its ok if that is the only thing your program is supposed to be doing anyways

pez 2019-10-26T19:25:14.135100Z

So in a ClojureScript REPL, using nREPL, is it possible to interrupt this?

((fn foo []
   (println "hello")
   (js/setTimeout foo 1000)))

thheller 2019-10-26T19:27:44.135700Z

no

pez 2019-10-26T19:27:45.135800Z

Or does that fall under this? > no you canโ€™t interrupt an infinite loop in JS

thheller 2019-10-26T19:28:06.136200Z

well it will have returned a number

thheller 2019-10-26T19:28:17.136500Z

you can use that number to call (js/clearTimeout num)

pez 2019-10-26T19:29:09.137200Z

Yeah, but thatโ€™s cheating. ๐Ÿ˜ƒ

thheller 2019-10-26T19:29:10.137300Z

but that only works if you hit it before the first repeat ๐Ÿ˜‰

thheller 2019-10-26T19:29:54.138200Z

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 ๐Ÿ˜›

pez 2019-10-26T19:29:56.138400Z

Indeed. It keeps printing here.

thheller 2019-10-26T19:31:32.139Z

you can override what setTimeout does but that gets into really messy territory ๐Ÿ˜›

pez 2019-10-26T19:31:51.139400Z

At least in a browser app I can reload the page.

pez 2019-10-26T19:33:24.140700Z

Iโ€™m asking this because weโ€™re implementing the interrupt op in Calva.

dominicm 2019-10-26T19:33:50.141900Z

Seems like there'd be some value in a debugging api provided by browsers that had these registries available.

thheller 2019-10-26T19:33:59.142200Z

interrupt doesn't even work reliably in clojure/JVM

๐Ÿ‘ 1
pez 2019-10-26T19:34:04.142400Z

And we can now stop trying to figure out how these constructs would be interrupted. ๐Ÿ˜ƒ