1
0
mirror of https://github.com/janet-lang/janet synced 2024-06-26 07:03:16 +00:00

More fixes to ev/gather (tested on httpf server).

This commit is contained in:
Calvin Rose 2023-02-05 10:21:37 -06:00
parent 4e8154cf8a
commit 67c474fc7a
2 changed files with 14 additions and 8 deletions

View File

@ -3583,16 +3583,18 @@
(,ev/deadline ,deadline nil ,f) (,ev/deadline ,deadline nil ,f)
(,resume ,f)))) (,resume ,f))))
(defn- cancel-all [fibers reason] (each f fibers (if (fiber/can-resume? f) (ev/cancel f reason)))) (defn- cancel-all [fibers reason] (each f fibers (ev/cancel f reason) (put fibers f nil)))
(defn- wait-for-fibers (defn- wait-for-fibers
[chan fibers] [chan fibers]
(defer (cancel-all fibers "parent canceled") (defer (cancel-all fibers "parent canceled")
(repeat (length fibers) (repeat (length fibers)
(def [sig fiber] (ev/take chan)) (def [sig fiber] (ev/take chan))
(unless (= sig :ok) (if (= sig :ok)
(cancel-all fibers "sibling canceled") (put fibers fiber nil)
(propagate (fiber/last-value fiber) fiber))))) (do
(cancel-all fibers "sibling canceled")
(propagate (fiber/last-value fiber) fiber))))))
(defmacro ev/gather (defmacro ev/gather
`` ``
@ -3600,13 +3602,16 @@
Returns the gathered results in an array. Returns the gathered results in an array.
`` ``
[& bodies] [& bodies]
(with-syms [chan res] (with-syms [chan res fset ftemp]
~(do ~(do
(def ,fset @{})
(def ,chan (,ev/chan)) (def ,chan (,ev/chan))
(def ,res @[]) (def ,res @[])
(,wait-for-fibers ,chan ,;(seq [[i body] :pairs bodies]
,(seq [[i body] :pairs bodies] ~(do
~(,ev/go (fn [] (put ,res ,i ,body)) nil ,chan))) (def ,ftemp (,ev/go (fn [] (put ,res ,i ,body)) nil ,chan))
(,put ,fset ,ftemp ,ftemp)))
(,wait-for-fibers ,chan ,fset)
,res)))) ,res))))
(compwhen (dyn 'net/listen) (compwhen (dyn 'net/listen)

View File

@ -955,6 +955,7 @@ static int line() {
break; break;
#ifndef _WIN32 #ifndef _WIN32
case 26: /* ctrl-z */ case 26: /* ctrl-z */
clearlines();
norawmode(); norawmode();
kill(getpid(), SIGSTOP); kill(getpid(), SIGSTOP);
rawmode(); rawmode();