Ste*_*Kuo 8 clojure core.async
在Clojure core.async中,通道和端口是一回事吗?如果不是有什么区别?在观看视频Timothy Baldridge - Core.Async时,他创建了一个频道
(def c (chan))
Run Code Online (Sandbox Code Playgroud)
然后
(<!! c)
Run Code Online (Sandbox Code Playgroud)
c是渠道还是国家的文件<!!(强调添加)
用法:(<!! port)从端口获取val .如果关闭,将返回nil.如果没有可用的话会阻止.
目前还不清楚核心.async文档.
Art*_*ldt 11
是的,chans是端口.
port是这些实现的协议的名称
(defprotocol ReadPort
(take! [port fn1-handler] "derefable val if taken, nil if take was enqueued"))
Run Code Online (Sandbox Code Playgroud)
用于impl/take:
(defn <!!
"takes a val from port. Will return nil if closed. Will block if nothing is available."
[port]
(let [p (promise)
ret (impl/take! port (fn-handler (fn [v] (deliver p v))))]
(if ret
@ret
(deref p))))
Run Code Online (Sandbox Code Playgroud)
并且在整个async.clj中使用名称port非常一致.从概念上讲,这很有用,因为并非core.async工作的所有内容都是一个通道.其他东西可以实现ReadPort和WritePort,因此可以很好地与core.async一起使用.
| 归档时间: |
|
| 查看次数: |
516 次 |
| 最近记录: |