2020-08-09 05:20:27 +00:00
|
|
|
(def channels
|
|
|
|
(seq [:repeat 5] (ev/chan 4)))
|
|
|
|
|
|
|
|
(defn writer [c]
|
|
|
|
(for i 0 3
|
2020-10-11 14:32:17 +00:00
|
|
|
(def item (string i ":" (mod (hash c) 999)))
|
2020-08-09 05:20:27 +00:00
|
|
|
(ev/sleep 0.1)
|
2020-10-07 00:07:29 +00:00
|
|
|
(print "writer giving item " item " to " c "...")
|
|
|
|
(ev/give c item))
|
2020-08-09 05:20:27 +00:00
|
|
|
(print "Done!"))
|
|
|
|
|
|
|
|
(defn reader [name]
|
|
|
|
(forever
|
2020-10-11 14:32:17 +00:00
|
|
|
(def [_ c x] (ev/rselect ;channels))
|
2020-10-11 14:07:11 +00:00
|
|
|
(print "reader " name " got " x " from " c)))
|
2020-08-09 05:20:27 +00:00
|
|
|
|
|
|
|
# Readers
|
|
|
|
(each letter [:a :b :c :d :e :f :g]
|
|
|
|
(ev/call reader letter))
|
|
|
|
|
|
|
|
# Writers
|
|
|
|
(each c channels
|
|
|
|
(ev/call writer c))
|