hi, the (go block in below function is not running if I comment the first (println call. If the entire function body is the go block, then the function is returning a channel instead of evaluating the go block. Please advise the reason
(defn test-db []
;(println "0. Testing database connection")
(go
(try
(let [_ (js [])))
]
(js/console.log "1. Database connected ok:>>>>" rows)
(
the result of evaluating a go block is a channel
user=> (a/go)
#object[clojure.core.async.impl.channels.ManyToManyChannel 0xadeb5a6 "clojure.core.async.impl.channels.ManyToManyChannel@adeb5a6"]
user=>
that is on clojure, not clojurescript, where things can be kind of funky due to the js event loop, but the fact that a (go ...) returns a channel is the sameHow should I change the function so that the node.js runtime evaluates the go block
what makes you thing it isn't being evaluated?
think
it is supposed to return a channel when evaluated
The console.log statements are not running.
The node repl likely never yields the event loop, or does it only at specific points, so stuff scheduled to run later (the go loop) never gets a chance to run
Oh ok.. Let me see if it works after I build and run instead of repl execution
You're right. When I compile and run the js file, the code worked fine
thank you
I wish I could force the repl to yield. I am not clear on how it all works under the hoods.. . There was some PR node js to allow await at the top level in the repl . https://github.com/nodejs/node/pull/15566 . Not sure how it works in the context of cljs repl evaluations