This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-06-23
Channels
- # announcements (1)
- # beginners (21)
- # calva (2)
- # cider (26)
- # clj-kondo (5)
- # cljdoc (4)
- # cljsrn (1)
- # clojure (42)
- # clojure-spec (5)
- # clojure-uk (1)
- # clojurescript (45)
- # cursive (5)
- # data-science (1)
- # datomic (5)
- # emacs (6)
- # fulcro (18)
- # hoplon (8)
- # immutant (1)
- # joker (9)
- # nyc (1)
- # off-topic (72)
- # re-frame (3)
- # reitit (1)
- # rewrite-clj (11)
- # shadow-cljs (9)
- # tools-deps (70)
Why can't I deref
promises from promesa
library in ClojureScript repl?
@ahmed1hsn Promesa supports deref
only on the JVM.
How can I get value of promise in CLJS?
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.
If we can't deref
value directly, then how do we get it?
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))))
Thanks.
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
there is a known problem with getting all the quoting and escaping to work for jvm opts with spaces in them
workaround:replace the spaces with commas (whitespace to clojure)
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
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)