In clojure we can have sliding-buffer chan; Is there any equivalent in 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.
You'll probably have to write something yourself, maybe with a goroutine in the middle that manages the buffer (maybe using deque ;)