Hi, I’m trying to use promesa in a ClojureScript project targeting React Native but I have some issues where documentation does not help. On the JVM the following core works fine, but when executing in ClojureScript on device I get an error:
(require '[promesa.core :as p])
=> nil
(p/resolved? (p/promise 42))
=> #object[Error Error: No protocol method IState.-resolved? defined for type object: [object Object]]
Thanks@mccraigmccraig … oh, right. Of course… can not work in JavaScript. Stupid me 🙈. My current solution is what you suggested with the atom… works fine.
👍
However the following does work:
(p/map println (p/promise 42))
42
=> #<Promise[~]>
But what about
@(p/promise 42)
=> #object[Error Error: No protocol method IDeref.-deref defined for type object: [object Object]]
The documentation says the @
reader macro does only work on the JVM, but deref
is not working, too:
(deref (p/promise 42))
=> #object[Error Error: No protocol method IDeref.-deref defined for type object: [object Object]]
When developing in the REPL I’d like to wait synchronously a promise to return its value…
@
is just sugar for deref
- neither will work in cljs because there is only a single thread in javascript, and if you block it the world stops
you can do something like
(defn grab [p]
(let [v-a (atom nil)]
(p/handle p
(fn [s f]
(reset! v-a [s f])))
v-a))
then deref the atom