[英]Is there any equivalent sliding-buffer chan in golang?
In clojure we can have sliding-buffer chan; 在Clojure中,我们可以使用滑动缓冲区chan。 Is there any equivalent in golang? golang中有什么等效的东西吗?
(require '[clojure.core.async :refer [go-loop <! >!! sliding-buffer chan]])
(def sliding-chan (chan (sliding-buffer 1)))
(go-loop []
(println "Received:" (<! sliding-chan))
(recur))
(dotimes [n 100]
(>!! sliding-chan n))
;;=> Received: 0
;;=> Received: 99
I don't think so. 我不这么认为。 Go has buffered channels but they will block when the channel is full. Go具有缓冲的通道,但是当通道已满时它们将阻塞。
You'll probably have to write something yourself, maybe with a goroutine in the middle that manages the buffer (maybe using deque ;) 您可能必须自己写点东西,也许在中间使用一个goroutine来管理缓冲区(也许使用deque ;)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.