[英]In Clojure, how to check if an object is a core.async channel?
There is a function chan
to create a channel. 还有一个功能
chan
创建一个通道。 But I don't see a chan?
但是我看不到a
chan?
. 。 How would I write a predicate
chan?
我将如何写谓词
chan?
that returns true for objects created by chan
? 对于
chan
创建的对象返回true?
I'm asking about both Clojure and ClojureScript. 我在问Clojure和ClojureScript。
Since channels are implemented as : 由于渠道实施为 :
(deftype ManyToManyChannel [^LinkedList takes ^LinkedList puts ^Queue buf closed ^Lock mutex add!]
...)
You can just check if it's an instance of ManyToManyChannel
: 您可以检查它是否是
ManyToManyChannel
的实例:
(import [clojure.core.async.impl.channels ManyToManyChannel])
(instance? ManyToManyChannel obj)
Or, if you care more about the protocols rather than the type itself, you can check if the object satisfies?
或者,如果您更关心协议而不是类型本身,则可以检查对象是否
satisfies?
one the the protocols: 协议之一:
(satisfies? clojure.core.async.impl.protocols/WritePort
obj)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.