funcool

A channel for discussing and asking questions about Funcool libraries https://github.com/funcool/
podviaznikov 2019-04-05T18:20:36.001900Z

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?

mccraigmccraig 2019-04-05T18:38:50.002500Z

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

mccraigmccraig 2019-04-05T18:41:14.003100Z

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

podviaznikov 2019-04-05T18:42:41.003600Z

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

podviaznikov 2019-04-05T18:43:14.004400Z

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