core-async

manas_marthi 2025-01-31T21:53:36.657019Z

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)
          (

2025-01-31T22:01:41.102029Z

the result of evaluating a go block is a channel

👍🏽 1
2025-01-31T22:03:27.072159Z

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 same

manas_marthi 2025-01-31T22:21:58.461419Z

How should I change the function so that the node.js runtime evaluates the go block

2025-02-01T01:15:53.975869Z

what makes you thing it isn't being evaluated?

2025-02-01T01:15:57.809219Z

think

2025-02-01T01:16:15.484909Z

it is supposed to return a channel when evaluated

manas_marthi 2025-02-01T01:48:43.852929Z

The console.log statements are not running.

2025-02-01T01:50:47.329129Z

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

manas_marthi 2025-02-01T02:16:50.721779Z

Oh ok.. Let me see if it works after I build and run instead of repl execution

manas_marthi 2025-02-01T03:47:41.533319Z

You're right. When I compile and run the js file, the code worked fine

manas_marthi 2025-02-01T03:47:48.214259Z

thank you

manas_marthi 2025-02-01T06:22:23.355459Z

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