简体   繁体   English

在Clojure中,如何检查对象是否为core.async通道?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM