Share your thoughts in the 2024 State of Clojure Survey!

Welcome! Please see the About page for a little more info on how this works.

+5 votes
in core.async by

When using channels, for example for streaming http bodies, it would be really helpful if there would be a chan? function to check whether a given var is a channel or not.

Aleph already does it like that in it's http-server/client implementation using lamina channels and it feels quite consistent.

It would of course also be more consistent with the rest of clojure to provide a type checking function for basic objects.

6 Answers

+1 vote
by
_Comment made by: thheller_

I would like to see the mentioned {{chan?}} {{read-port?}} {{write-port?}} predicates as they would make writing some clojure.spec/fdefs simpler (and portable to cljs.core.async).
+1 vote
by

Comment made by: jwr

I have just reached a point where I need to spec structures, which contain channels that are passed around. I looked for a chan? predicate that I could use for my specs, but found none, and ended up here.

Answering Rich's quote: yes, I think predicates for "popular" interfaces are needed — the spec writer might not necessarily know (or care) which interfaces must be implemented. I have no idea what a ReadPort is, and yet I'm writing core.async code and I need to spec that something is "a channel".

0 votes
by

Comment made by: davidrupp

Implement chan? predicate.

0 votes
by

Comment made by: halgari

I'm in favor of this, but last time I asked Rich about it his quote was "do you want a predicate for every single interface?".

Due to the implementation of core.async you'd probably need two additional predicates. One for read-port? and write-port?. You can use (satisfies? clojure.core.async.impl.protocols/ReadPort ...) but that's an internal implementation, so I'd rather have a new predicate than to tell people to touch the innards of core.async. But this call is up to Rich.

0 votes
by

Comment made by: exi

I understand that reasoning. But then we would have to step up on documentation and provide a way to easily determine which interfaces are implemented by the return values of for example (chan). For me, going into the innards of core.async and trying to determine which interfaces I want, especially on very basic things like a channel, is not a user friendly approach at all.

0 votes
by
...