This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-25
Channels
- # beginners (152)
- # boot (4)
- # bristol-clojurians (1)
- # cider (1)
- # cljs-dev (176)
- # clojure (104)
- # clojure-china (2)
- # clojure-uk (6)
- # clojurescript (6)
- # core-async (23)
- # cursive (4)
- # datomic (3)
- # devops (1)
- # duct (32)
- # events (1)
- # fulcro (9)
- # hoplon (2)
- # jobs-discuss (9)
- # lein-figwheel (2)
- # leiningen (3)
- # off-topic (19)
- # pedestal (2)
- # portkey (14)
- # re-frame (20)
- # reagent (41)
- # rum (4)
- # shadow-cljs (26)
- # tools-deps (1)
- # unrepl (5)
I'm using core.async trying to create a macron a cljc file like this:
(defmacro go-catch [& body]
`(async/go
(try
~@body
(catch #?(:clj Throwable :cljs :default) e# e#))))
the macro works fine on clojure, but on cljs every time I try to run it I get: java is not defined
, you know what that's about?
@wilkerlucio If you load that macro using JVM ClojureScript, then the macro is being compiled as Clojure, thus taking the :clj
branch and putting java.lang.Throwable
into your ClojureScript code, I would guess.
humm, do you have an example on how should I handle this? I have to make a separated version for cljs?
This is the if-cljs
stuff.. where you detect if you macro is being expanded for use in ClojureScript.
trying to find some examples for it, but google is not helping me much... do you know some place where I can see that in use?
nevermind, just found a thread with it 🙂
but that still doesn't seem to work in my case =/
you mean the if-cljs
?
By the way, vote for https://dev.clojure.org/jira/browse/CLJ-1293 as it would provide a portable solution 🙂
sure, I tried this:
(defmacro if-cljs
[then else]
(if (:ns &env) then else))
(defmacro go-catch [& body]
`(async/go
(try
~@body
(catch (if-cljs :default Throwable) e# e#))))
and just voted, this error handling is surely something would be nice to have portable
unquoting seems to break the compilation
@wilkerlucio Right, your code above appears to be correct.
well, I got it working, but I had to duplicate the code across 2 different namespaces
I made async-clj
and async-cljs
, and the consumers now require like this:
[#?(:clj com.wsscode.common.async-clj
:cljs com.wsscode.common.async-cljs) :refer [go-catch]]
not ideal, but works, when that jira gets in will be awesome