Fork me on GitHub
#beginners
<
2019-06-23
>
Ahmed Hassan07:06:41

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

valtteri11:06:23

@ahmed1hsn Promesa supports deref only on the JVM.

Ahmed Hassan11:06:17

How can I get value of promise in CLJS?

valtteri11:06:02

In js.you 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 http://funcool.github.io/promesa/latest/#asyncawait-syntax 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?

lilactown15:06:59

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

valtteri15:06:12

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))))

Aron17:06:28

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}"

Aron17:06:41

@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?

seancorfield17:06:46

@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.

seancorfield17:06:06

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

seancorfield17:06:17

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

Aron17:06:30

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

seancorfield17:06:09

In one Terminal:

(! 649)-> clj -J-Dclojure.server.jvm="{:port,5555,:accept,clojure.core.server/io-prepl}"
Clojure 1.10.1
user=> 
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
Trying 127.0.0.1...
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\")"}
:repl/quit
Connection closed by foreign host.

Sun Jun 23 10:12:02
(sean)-(jobs:0)-(~/clojure/learning/guestbook)
(! 527)-> 
(I should have used telnet 127.0.0.1 5555 really)

👍 4
Aron17:06:18

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

4
Ludwig23:06:55

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?