Hello!
I was interested in trying to wrap some callback-hellish JS async functionality into something that would look (and work) like a sync call.
I thought that it could be some kind of function which internally uses core.async but does not expose this.
That is instead of having some function with callback on completion
(.findSomething jsLib (fn [res] (println res)))
I would like to have a sync-variant of it, something like this
(defn findSomething []
"returns res"
(let [c (chan)]
(go (!< (.findSomething jsLib (fn [res] (put! c res)))))))
(println (findSomething)) ;; => prints "res" value
It would work if go-macro returned last *value* read from the channel. But go macro returns a *channel* that contains the result. So to read it in clojurescript I have to ironically wrap go in go again.
Seems like when you started using channels there's no way out of this :)
On JVM I could just use <!! in this situation, but it is not supported in ClojureScript.
Wanted some advice/pointers from experienced programmers as I've just started and might get something completely wrong :)
Thanks in advance,
Dmitry.