mirror of
https://github.com/janet-lang/janet
synced 2024-12-29 18:00:26 +00:00
Merge pull request #1181 from chris-chambers/ev-gather-cancel
Ensure ev/gather fibers are fully canceled on error
This commit is contained in:
commit
88ba99b87e
@ -3663,17 +3663,21 @@
|
||||
(,ev/deadline ,deadline nil ,f)
|
||||
(,resume ,f))))
|
||||
|
||||
(defn- cancel-all [fibers reason] (each f fibers (ev/cancel f reason) (put fibers f nil)))
|
||||
(defn- cancel-all [chan fibers reason]
|
||||
(each f fibers (ev/cancel f reason))
|
||||
(let [n (length fibers)]
|
||||
(table/clear fibers)
|
||||
(repeat n (ev/take chan))))
|
||||
|
||||
(defn- wait-for-fibers
|
||||
[chan fibers]
|
||||
(defer (cancel-all fibers "parent canceled")
|
||||
(defer (cancel-all chan fibers "parent canceled")
|
||||
(repeat (length fibers)
|
||||
(def [sig fiber] (ev/take chan))
|
||||
(if (= sig :ok)
|
||||
(put fibers fiber nil)
|
||||
(do
|
||||
(cancel-all fibers "sibling canceled")
|
||||
(cancel-all chan fibers "sibling canceled")
|
||||
(propagate (fiber/last-value fiber) fiber))))))
|
||||
|
||||
(defmacro ev/gather
|
||||
|
@ -168,6 +168,13 @@
|
||||
(assert (deep= @[] (ev/gather)) "ev/gather 2")
|
||||
(assert-error "ev/gather 3" (ev/gather 1 2 (error 3)))
|
||||
|
||||
(var cancel-counter 0)
|
||||
(assert-error "ev/gather 4.1" (ev/gather
|
||||
(defer (++ cancel-counter) (ev/take (ev/chan)))
|
||||
(defer (++ cancel-counter) (ev/take (ev/chan)))
|
||||
(error :oops)))
|
||||
(assert (= cancel-counter 2) "ev/gather 4.2")
|
||||
|
||||
# Net testing
|
||||
# 2904c19ed
|
||||
(repeat 10
|
||||
|
Loading…
Reference in New Issue
Block a user