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

Tried docs https://clojuredocs.org/clojure.core.async 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))
1 Like

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

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.