Fork me on GitHub
#core-async
<
2022-04-22
>
winsome17:04:13

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

winsome18:04:09

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).

didibus03:04:47

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

Andrew14:04:51

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

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