-
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Macro idea for async instrumentation: >defn-go #24
Comments
>defn-go
This sounds interesting. A couple of quick thoughts off the top of my head:
|
The wrapping of the body of the fn with
I was also thinking Yes I'd have to disable the regular "outstrumenting" with orchestra, as the regular return value (a channel) would fail the spec. I can set that in the metadata on |
I think I wanna have something like this in there—async is obviously hugely important—but I'll have to do some more thinking and a bit of exploratory programming to be able to comment on this any further and it'll probably be a while because right now I'm focused on getting 0.4.0 out the door. I'm setting the milestone to 0.5.0 for now. |
Your comment has prompted me to get back to this and post a simple macro I've started using. Right now it's CLJS only, and doesn't support Other than the I added a bit of a hack to make failure messages more informative. Instead of emitting (defmacro >defn-go [fn-name & fn-tail]
(let [front-stuff (take-while (complement vector?) fn-tail)
rest (drop (count front-stuff) fn-tail)
[args spec & body] rest
spec* (concat (drop-last spec)
[`any?])
ret-spec (last spec)
ret-spec-kw (keyword (str ana/*cljs-ns*) (str (name fn-name) "-return"))]
`(do
(cljs.spec.alpha/def ~ret-spec-kw ~ret-spec)
(ghostwheel.core/>defn ~fn-name ~@front-stuff ~args [~@spec*]
(go (cljs.spec.alpha/assert ~ret-spec-kw (do ~@body))))))) |
👋 Hi. I'm posting this same comment to all issue threads to just give a quick heads up that the project, despite rumours and some evidence to the contrary, is not dead. It was hibernating for a little while and now nearing the long-awaited next release, which will fix some long-standing issues (and introduce some breaking changes to the config). I'll be reviewing all open issues and PRs over the next couple of weeks, so stay tuned and thanks for the patience. See also this Slack thread |
I have a lot of core.async in my (CLJS) app. I guess spec + core.async is a very big topic, and at some point the Clojure community will probably come up with a powerful approach. In the mean time, this is more of a low-hanging-fuit idea that could be very helpful.
In async code there are a lot of functions where the top level form is
(go ...)
. Often the return value is discarded, but sometimes not, e.g. an async function to fetch a value from a server via HTTP.The normal return spec is pretty much useless, as such functions always return a channel.
What you really want is to be able to spec the (single) value that is sent over the returned channel. From an instrumentation point of view, this could be done if we lift the
(go ...)
to be part of the macro that defines the function (and the specs), i.e. something like this:which, when instrumented, would expand to something along the lines of
I'm intending on having a crack at implementing this macro myself. Any advice would be greatly appreciated. If it sounds like something that could be a contribution, so much the better.
The text was updated successfully, but these errors were encountered: