Skip to content

Instantly share code, notes, and snippets.

@rarous
Created July 18, 2013 05:05
Show Gist options
  • Save rarous/6026837 to your computer and use it in GitHub Desktop.
Save rarous/6026837 to your computer and use it in GitHub Desktop.
(require '[clojure.core.async :as async :refer :all])
(defn customer [i ch]
(go (>! ch i)))
(defn barber [ch]
(go (while true
(println "cuts hair of " (<! ch)))))
(let
[ch (chan (dropping-buffer 3))]
(barber ch)
(dotimes [i 1000]
(customer i ch)))
@rarous
Copy link
Author

rarous commented Jul 18, 2013

Trik je v tom, že holičství jako takové je kanál a čekárna v něm jeho buffer. Vzhledem k tomu, že když je čekárná plná, další nebereme, je buffer dropping. Když není holičství kanálu žádný zákazník, holič spí.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment