1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-17 14:14:49 +00:00
janet/examples/select.janet
2020-10-11 09:14:14 -05:00

23 lines
449 B
Clojure

(def channels
(seq [:repeat 5] (ev/chan 4)))
(defn writer [c]
(for i 0 3
(ev/sleep 0.1)
(print "writer giving item " i " to " c "...")
(ev/give c (string "item " i)))
(print "Done!"))
(defn reader [name]
(forever
(def [_ c x] (ev/select ;channels))
(print "reader " name " got " x " from " c)))
# Readers
(each letter [:a :b :c :d :e :f :g]
(ev/call reader letter))
# Writers
(each c channels
(ev/call writer c))