mirror of
https://github.com/janet-lang/janet
synced 2024-12-25 07:50:27 +00:00
Add another select example.
This commit is contained in:
parent
cb4903fa86
commit
bbe10e4938
37
examples/select2.janet
Normal file
37
examples/select2.janet
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
###
|
||||||
|
### examples/select2.janet
|
||||||
|
###
|
||||||
|
### Mix reads and writes in select.
|
||||||
|
###
|
||||||
|
|
||||||
|
(def c1 (ev/chan 40))
|
||||||
|
(def c2 (ev/chan 40))
|
||||||
|
(def c3 (ev/chan 40))
|
||||||
|
(def c4 (ev/chan 40))
|
||||||
|
|
||||||
|
(def c5 (ev/chan 4))
|
||||||
|
|
||||||
|
(defn worker
|
||||||
|
[c n x]
|
||||||
|
(forever
|
||||||
|
(ev/sleep n)
|
||||||
|
(ev/give c x)))
|
||||||
|
|
||||||
|
(defn writer-worker
|
||||||
|
[c]
|
||||||
|
(forever
|
||||||
|
(ev/sleep 0.2)
|
||||||
|
(print "writing " (ev/take c))))
|
||||||
|
|
||||||
|
(ev/call worker c1 1 :item1)
|
||||||
|
(ev/sleep 0.2)
|
||||||
|
(ev/call worker c2 1 :item2)
|
||||||
|
(ev/sleep 0.1)
|
||||||
|
(ev/call worker c3 1 :item3)
|
||||||
|
(ev/sleep 0.2)
|
||||||
|
(ev/call worker c4 1 :item4)
|
||||||
|
(ev/sleep 0.1)
|
||||||
|
(ev/call worker c4 1 :item5)
|
||||||
|
(ev/call writer-worker c5)
|
||||||
|
|
||||||
|
(forever (pp (ev/rselect c1 c2 c3 c4 [c5 :thing])))
|
Loading…
Reference in New Issue
Block a user