nbb

Chris McCormick 2024-03-05T21:43:32.470139Z

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.

borkdude 2024-03-05T21:48:15.939179Z

In the anonymous function, where do you expect recur to go next?

borkdude 2024-03-05T21:48:33.115369Z

you probably want to write down instead

borkdude 2024-03-05T21:48:48.891669Z

since #(recur ...) means that the anonymous function itself will be called

🤯 2
borkdude 2024-03-05T21:50:09.483109Z

the error message could be better though

Chris McCormick 2024-03-05T21:50:31.891109Z

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. 😬

borkdude 2024-03-05T21:51:48.991979Z

async should not smash the stack I think

Chris McCormick 2024-03-05T21:51:49.697729Z

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!

borkdude 2024-03-05T21:52:06.061669Z

down

👍 1
borkdude 2024-03-05T21:53:07.218609Z

kondo would also warn about that recur issue btw:

Chris McCormick 2024-03-05T21:53:38.804989Z

Ah my kondo must be out of date, will update.

borkdude 2024-03-05T21:53:58.018919Z

neh, it does this since ages

Chris McCormick 2024-03-05T21:54:32.065129Z

Hm strange I'm not seeing an error. 🤔

borkdude 2024-03-05T21:54:32.503759Z

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)

Chris McCormick 2024-03-05T21:55:21.273039Z

Ok, thanks, I will try again with this pattern in the morning.

Chris McCormick 2024-03-05T21:56:19.242939Z

Oh, I silenced kondo for the whole namespae by accident when trying to silence a different warning, so never mind about that.

Chris McCormick 2024-03-06T21:16:04.592929Z

Thank you, your solution fixed my issue with no stack smash.

👍 1