mirror of
https://github.com/janet-lang/janet
synced 2024-11-19 07:04:48 +00:00
212479188a
This is more correct and mirrors the way marshal -> unmarshal works.
19 lines
385 B
Plaintext
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)
|