brave-clojure-web icon indicating copy to clipboard operation
brave-clojure-web copied to clipboard

Fix inaccurate explanation in core-async.html

Open imrekoszo opened this issue 8 years ago • 0 comments

The core.async chapter has the following sentence when explaining how buffers work:

With a dropping buffer, he’d just knock the freshest batch off of the shelf and put his new batch in that space.

That to me sounds incorrect as dropping-buffer discards new puts when it's full rather than discarding an already buffered item, so I updated the sentence to:

With a dropping buffer, he’d just throw away the new batch he has just made if the shelf is full.

Code sample demonstrating how dropping-buffer works:

(require '[clojure.core.async :as a])
; => nil

(def ketchup-shelf (a/chan (a/dropping-buffer 5)))
; => #'user/ketchup-shelf

(dotimes [batch-number 10]
  (a/>!! ketchup-shelf batch-number))
; => nil

(dotimes [_ 5]
  (println (a/<!! ketchup-shelf)))
; => 0
; => 1
; => 2
; => 3
; => 4
; => nil

If dropping-buffer worked the way the article currently explains, the output would be:

(dotimes [_ 5]
  (println (a/<!! ketchup-shelf)))
; => 0
; => 1
; => 2
; => 3
; => 9
; => nil

imrekoszo avatar Apr 05 '17 12:04 imrekoszo