How to detect if a value is a channel in ClojureScript?


#1

Tried docs https://clojuredocs.org/clojure.core.async but found nothing like chan?. How to tell if a value is a channel?


#2

It is a bit ugly at the moment but you can use the core.async protocols and check for those.

(ns foo.util
  (:require [cljs.core.async.impl.protocols :as async-prot]))

(defn chan? [x]
  (satisfies? async-prot/ReadPort x))

#3

I’ve been using these:

clojure

(defn channel?
  [x]
  (satisfies? clojure.core.async.impl.protocols/Channel x))

clojurescript

(defn channel?
  [x]
  (satisfies? cljs.core.async.impl.protocols/Channel x))