virtual thread cult

This commit is contained in:
Michiel Borkent 2025-02-21 15:32:45 +01:00
parent 6be0b5bddf
commit aee22beab9

View file

@ -54,15 +54,12 @@
([f] (thread-call f :mixed)) ([f] (thread-call f :mixed))
([f workload] ([f workload]
(let [c (async/chan 1) (let [c (async/chan 1)
binds (vars/get-thread-binding-frame)
returning-to-chan (fn [bf] returning-to-chan (fn [bf]
#(try #(try
(when-some [ret (bf)] (when-some [ret (bf)]
(async/>!! c ret)) (async/>!! c ret))
(finally (async/close! c)))) (finally (async/close! c))))
f (fn [] f (vars/binding-conveyor-fn f)]
(vars/reset-thread-binding-frame binds)
(f))]
(-> f #_bound-fn* returning-to-chan (dispatch/exec workload)) (-> f #_bound-fn* returning-to-chan (dispatch/exec workload))
c))) c)))
@ -72,16 +69,14 @@
f when completed, then close." f when completed, then close."
[f] [f]
(let [c (async/chan 1)] (let [c (async/chan 1)]
(let [binds (vars/get-thread-binding-frame)] (let [returning-to-chan (fn [bf]
#(try
(when-some [ret (bf)]
(async/>!! c ret))
(finally (async/close! c))))
f (vars/binding-conveyor-fn f)]
(.execute virtual-executor (.execute virtual-executor
(fn [] (-> f returning-to-chan)))
(vars/reset-thread-binding-frame binds)
(try
(let [ret (f)]
(when-not (nil? ret)
(async/>!! c ret)))
(finally
(async/close! c))))))
c)) c))
(defn thread (defn thread