Fork me on GitHub
#funcool
<
2019-04-05
>
podviaznikov18:04:36

Hi, I'm have a question about using promesa async/await in clojurescript(in node). I have this function:

(defn get-json [url]
  (let [result 
          (async
            (dotimes [i 3]
              (p/await (p/delay 100))
              (println "i=" i))
            [{:a "hello"}])]
            @result
            )
And I required
[promesa.core :as p]
            [promesa.async-cljs :refer-macros [async]]
However, when I call get-json I'm getting an error:
(montaigne.fns/get-json "aa")
Execution error (Error) at (<cljs repl>:1).
No protocol method IDeref.-deref defined for type object: [object Promise]
Any hints? It should be possible to have synchronous looking code in ClojureScript running in node, right?

mccraigmccraig18:04:50

@podviaznikov cljs promesa doesn't support deref aka @ - once you are in async-land, there is no escape!

mccraigmccraig18:04:14

(instead of derefing, compose further then actions onto your promises)

podviaznikov18:04:41

yeah, makes sense. Thanks 🙏 I wish there was escape:)

podviaznikov18:04:14

Ok, There might be sync http request in node. https://www.npmjs.com/package/sync-request. I'm writing CLI, so for me sync requests are fine, no need for async io