Created
July 18, 2013 05:05
-
-
Save rarous/6026837 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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í.