Fork me on GitHub

Is there a predicate that can test whether something is a channel?

Alex Miller (Clojure team)17:04:55

it's a little more subtle than it looks as channels are actually made up of read ports and write ports and some channels only do part of that

Ben Sless18:04:47

Instead of chan?, how about writable? and readable?

Alex Miller (Clojure team)18:04:00

I guess I'd ask the OP what the context for wanting this is


My problem is that sometimes a channel gets put in another channel, and I need to take the value from it. Until I figure out where it's coming from, I'm currently just doing a (try (<! maybe-chan) (catch Exception _ maybe-chan).


I've had success with (instance? ManyToManyChannel v)


yeah it’s a bit sloppy, but we do (def AsyncChan (class (async/chan))) in a schemata file you can use that with checking e.g.

(s/defn my-f [ch :- AsyncChan] ,,,)
or test directly with (instance? AsyncChan v) as @U0K064KQV suggested