Should this work in nbb?
(defn down [i]
(if (> i 0)
(js/setTimeout #(recur (dec i)) 1000)
i))
(down 5)
I get this when I run it:
60: (defn down [i]
61: (if (> i 0)
62: (js/setTimeout #(recur (dec i)) 1000)
^--- No item 0 in vector of length 0
63: i))
64:
65: (down 5)
Can't work out if it's a general cljs async/recur issue or nbb or I am holding it wrong.In the anonymous function, where do you expect recur to go next?
you probably want to write down instead
since #(recur ...) means that the anonymous function itself will be called
the error message could be better though
Ok thank you for fixing my brain! I'm using recur because I need to run 16k async functions and every other way I tried is smashing the stack. 😬
async should not smash the stack I think
If I call done I end up with the same issue. Will have a think about this some more in the morning, thanks for your help!
down
kondo would also warn about that recur issue btw:
Ah my kondo must be out of date, will update.
neh, it does this since ages
Hm strange I'm not seeing an error. 🤔
No stack issues in this example:
(defn down [i]
(if (> i 0)
(do (prn :i i)
(js/setTimeout #(down (dec i)) 0))
i))
(down 50000)Ok, thanks, I will try again with this pattern in the morning.
Oh, I silenced kondo for the whole namespae by accident when trying to silence a different warning, so never mind about that.
Thank you, your solution fixed my issue with no stack smash.