1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-01 16:13:02 +00:00

Add ev/select and ev/rselect initial implementation.

Getting closer to a CSP implmententation. Probably
useful to move scheduling fields outside of fibers
and into an external table.
This commit is contained in:
Calvin Rose
2020-08-09 00:20:27 -05:00
parent 78ffb63429
commit fb26c9b2c4
4 changed files with 124 additions and 22 deletions

22
examples/select.janet Normal file
View File

@@ -0,0 +1,22 @@
(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 (ev/select ;channels))
(print "reader " name " got " (ev/take c) " from " c)))
# Readers
(each letter [:a :b :c :d :e :f :g]
(ev/call reader letter))
# Writers
(each c channels
(ev/call writer c))