~subsetpark/bagatto

499fe3c31dda351c91b0d412ddabb92547401946 — Zach Smith 2 months ago d4f43c8
Use spork/ev-utils for parallel work
1 files changed, 4 insertions(+), 11 deletions(-)

M src/core.janet
M src/core.janet => src/core.janet +4 -11
@@ 1,5 1,6 @@
(import spork/path)
(import spork/temple)
(import spork/ev-utils)

(import /src/util)
(import /src/error)


@@ 79,16 80,8 @@
  [output-dir writer-specs]

  (let [spec-count (length writer-specs)
        handler (writers/write-handler output-dir @{})
        supervisor (ev/chan spec-count)
        fibers (map |(ev/go (fn [] (handler $)) nil supervisor) writer-specs)]
        handler (writers/write-handler output-dir @{})]

    (printf "Writing %d output specs..." spec-count)

    (repeat spec-count
      (let [[sig fiber] (ev/take supervisor)]
        (unless (= sig :ok)
          (each f fibers (ev/cancel f "sibling canceled"))
          (propagate (fiber/last-value fiber) fiber)))))

  (printf "Done writing."))
    (ev-utils/pmap handler writer-specs)
    (printf "Done writing.")))