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


Tried docs but found nothing like chan?. How to tell if a value is a channel?


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


I’ve been using these:


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


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