1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-19 07:04:48 +00:00
janet/examples/threads.janet
Calvin Rose 212479188a Have separate encode and decode dicts for threads
This is more correct and mirrors the way marshal -> unmarshal works.
2019-12-01 21:53:39 -06:00

19 lines
385 B
Plaintext

(defn worker-main
[parent]
(def name (thread/receive parent))
(for i 0 10
(os/sleep 1)
(print "thread " name " wakeup no. " i))
(thread/send parent :done))
(defn make-worker
[name]
(-> (thread/new) (thread/send worker-main) (thread/send name)))
(def bob (make-worker "bob"))
(os/sleep 0.5)
(def joe (make-worker "joe"))
(thread/receive bob)
(thread/receive joe)