mirror of
https://github.com/janet-lang/janet
synced 2024-11-14 12:44:49 +00:00
0a1c93b869
Easy way to make arbitrary functions in C async.
23 lines
477 B
Clojure
23 lines
477 B
Clojure
(defn dowork [name n]
|
|
(print name " starting work...")
|
|
(os/execute [(dyn :executable) "-e" (string "(os/sleep " n ")")])
|
|
(print name " finished work!"))
|
|
|
|
# Will be done in parallel
|
|
(print "starting group A")
|
|
(ev/call dowork "A 2" 2)
|
|
(ev/call dowork "A 1" 1)
|
|
(ev/call dowork "A 3" 3)
|
|
|
|
(ev/sleep 4)
|
|
|
|
# Will also be done in parallel
|
|
(print "starting group B")
|
|
(ev/call dowork "B 2" 2)
|
|
(ev/call dowork "B 1" 1)
|
|
(ev/call dowork "B 3" 3)
|
|
|
|
(ev/sleep 4)
|
|
|
|
(print "all work done")
|