This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # announcements (13)
- # babashka (7)
- # beginners (35)
- # calva (23)
- # chlorine-clover (6)
- # cider (12)
- # clj-kondo (6)
- # clojure (31)
- # clojure-dev (20)
- # clojure-europe (4)
- # clojure-norway (4)
- # clojure-uk (1)
- # clojurescript (62)
- # fulcro (6)
- # google-cloud (1)
- # lsp (2)
- # malli (13)
- # meander (6)
- # music (1)
- # off-topic (19)
- # practicalli (2)
- # re-frame (7)
- # reagent (25)
- # reitit (5)
- # releases (1)
- # reveal (3)
- # shadow-cljs (90)
- # tools-build (18)
- # tools-deps (1)
Hi. is there a way to check if I am inside a core.async go block? I'm writing a macro that calls
<! but i want to fail before reaching the line calling
If you're doing it in a macro, then
<! won't compile if it's not in a
go block anyway.
But I have to ask, why?
i understand it won't compile, my problem is that it will raise the error too late for me. i'd like to write a macro that will fail immediately if it is not in a go block, similar to calling
i am writing a macro that does two things:
1. send an async http request. the http-send fn returns a channel
2. take from that channel using
if my macro is called outside of a go block, it will fail on 2. i want it to fail before 1 occurs i.e. before sending the http request
Roughly, something like
(defmacro send! [req] `(let [p# (a/promise-chan)] (http/send req (fn [resp#] (a/put! p# resp#))) (a/<! p#)))
It won't. This macro won't even compile (not talking about run, but compile) if it's not in a go block.
ach, my bad,
<! is defined as a function and not a macro, it will only throw at runtime
which brings us back to my other recommendation anyway, use a function and not a macro, return a channel and handle it in the go block
Which, when you say "I have a macro that does two things", should raise a flag - why not compose two separate things?
the first stage is happening in a different function that sends http and async puts on a chan and returns that chan
Use some function like this to turn an async function to a function which returns a channel:
(defn afn->p [af] (fn [ctx] (let [p (a/promise-chan)] (af ctx (fn [result] (a/put! p result))) p)))
So just work with a bare channel. In this context you should treat it like a promise or a completion stage
thanks. i was hoping theres a way around that 😕 i'm writing a helper function to on board code which doesn't yet support async.core channels
Can you elaborate a bit? core.async is great but it's not necessarily a fit in every situation. Why should code support it to begin with? Shouldn't it be generic and be open to adaptation by building an abstraction layer / good separation of existing layers?
<!! will take from a channel in a blocking way. That might be what you want.
But to @UK0810AQ2’s point - core.async isn’t necessarily a fit in every situation
(clojure.string/split "EURJPY.COMP" #".") this command is not splitting the string on the basis of "." how can I split it ?
Am I crazy for thinking
(apply juxt) should work on a list, just like it does with a vector?
the problem is that
'(true? false? string?) doesn’t evaluate to what you think it does. evaluate it in the repl
Ahh I see, it's creating a list of symbols… I guess I need to refresh my memory on how quoting works