Fork me on GitHub
Ahmed Hassan07:06:41

Why can't I deref promises from promesa library in ClojureScript repl?


@ahmed1hsn Promesa supports deref only on the JVM.

Ahmed Hassan11:06:17

How can I get value of promise in CLJS?


In can’t block the only thread there is so you need to use callbacks. Promises and async/await are just syntactic sugar over callbacks. You can get close to synchronous looking code with this macro which is probably what you’re looking for.

Ahmed Hassan14:06:45

If we can't deref value directly, then how do we get it?


use the then or map function, as documented in the link that valterri posted


Here is a simple example

(def m {:a 1 :b "kissa"}) ;; This is our value

(-> (p/promise m) ;; Promise that resolves to 'our value'
    (p/then (fn [m] ;; function that gets called when promise is resolved
              (prn "Value is here!" m))))


what should I expect to happen if I run clj -J-Dclojure.server.jvm="{:port 5555 :accept clojure.core.server/io-prepl}" ? because I thought there will be a server open on 5555, but that doesn't happen. The repl opens, but I don't see anything on port 5555

Alex Miller (Clojure team)17:06:47

there is a known problem with getting all the quoting and escaping to work for jvm opts with spaces in them

Alex Miller (Clojure team)17:06:01

workaround:replace the spaces with commas (whitespace to clojure)

Alex Miller (Clojure team)17:06:30

clj -J-Dclojure.server.jvm="{:port,5555,:accept,clojure.core.server/io-prepl}"


@alexmiller thanks I see this

tcp6       0      0 localhos:personal-agent [::]:*                  LISTEN      29696/java
but I can't really connect to it. What would be a fool-proof way to test that it works?


@ashnur If you have a prepl running on a socket, you should be able to telnet localhost 5555 and type in a Clojure expression and press return — and it should produce output.


Bear in mind, the prepl offers no prompt (it’s meant to be consumed by programs, not people).


And you can type :repl/quit to get out of it.


@seancorfield thanks, it works, I was just being confused 😞 as usual


In one Terminal:

(! 649)-> clj -J-Dclojure.server.jvm="{:port,5555,:accept,clojure.core.server/io-prepl}"
Clojure 1.10.1
In another Terminal:
(! 526)-> telnet localhost 5555
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying fe80::1...
telnet: connect to address fe80::1: Connection refused
Connected to localhost.
Escape character is '^]'.
(System/getProperty "user.dir")
{:tag :ret, :val "\"/Users/sean/clojure\"", :ns "user", :ms 17, :form "(System/getProperty \"user.dir\")"}
Connection closed by foreign host.

Sun Jun 23 10:12:02
(! 527)-> 
(I should have used telnet 5555 really)

👍 4

I am trying to make this work with conjure and for a while I thought that for some reason I can't connect to the REPL, but I can. Thanks again


Hi guys ! do anyone know if it's possible to use re-natal for web too? I would like to have web and mobile in the same code base . There is a react native web project that ports native ui to web components, would it work in re-natal too?