~subsetpark/bagatto

e57261b79b52600c55a95b050fb4ca1228e1a8bd — Zach Smith a month ago 3491892
Format
2 files changed, 9 insertions(+), 9 deletions(-)

M src/threads.janet
M test/threads.janet
M src/threads.janet => src/threads.janet +2 -2
@@ 83,9 83,9 @@
  [jobs thread-init]

  (print "Beginning " (length jobs) " jobs...")
  

  (map thread-init jobs)
  

  (let [res @{}]
    (while (< (length res) (length jobs))
      (match (thread/receive timeout)

M test/threads.janet => test/threads.janet +7 -7
@@ 10,19 10,19 @@
(deftest distribute
  (let [jobs (seq [x :range [0 10]] (dist-job x))
        out (threads/distribute jobs thread-init)]
    (is (==  @{0 true 2 true 1 true 3 true 5 true 6 true 4 true 8 true 7 true 9 true} out))))
    (is (== @{0 true 2 true 1 true 3 true 5 true 6 true 4 true 8 true 7 true 9 true} out))))

(defn pool-init [] ())
(defn do-work
    [parent self msg _state]
    (match msg
      :die (do (:send parent self)
               (thread/exit))
      [:consume n] (spit (string "test/support/pool/" n) "ok")))
  [parent self msg _state]
  (match msg
    :die (do (:send parent self)
           (thread/exit))
    [:consume n] (spit (string "test/support/pool/" n) "ok")))

(deftest pool
  (os/shell "rm test/support/pool/*")
  

  (threads/demand-pipeline (range 0 10)
                           pool-init
                           do-work)