core: Phase 4 — move future-done?/future-cancelled? to the overlay

Pure reads of the future's :cached/:cancelled slots over future? + get.
future? stays native (deref/future-cancel/realized? call it), as do future-call
and future-cancel (OS threads). Covered by the existing futures spec.
This commit is contained in:
Yogthos 2026-06-07 21:41:11 -04:00
parent a9403e26b0
commit 790f54d2b3
2 changed files with 10 additions and 6 deletions

View file

@ -293,3 +293,11 @@
(jolt.host/ref-put! vol :val newval) newval)
(defn vswap! [vol f & args]
(vreset! vol (apply f (get vol :val) args)))
;; Future status predicates — pure reads of the future's :cached/:cancelled slots.
;; future? stays native (deref/future-cancel/realized? call it); future-call and
;; future-cancel stay native too (OS threads).
(defn future-done? [x]
(if (future? x) (boolean (get x :cached)) (throw "future-done? requires a future")))
(defn future-cancelled? [x]
(and (future? x) (boolean (get x :cancelled))))

View file

@ -1904,10 +1904,8 @@
(def res (fut :res))
(if (= :error (in res 0)) (error (in res 1)) (in res 1)))
(defn core-future-done? [x]
(if (core-future? x) (truthy? (x :cached))
(error "future-done? requires a future")))
(defn core-future-cancelled? [x] (and (core-future? x) (truthy? (x :cancelled))))
# future-done? / future-cancelled? now live in the Clojure collection tier (pure
# reads of :cached/:cancelled). core-future? stays — deref/future-cancel call it.
# Janet OS threads can't be interrupted, so the worker still runs to completion
# in the background; we can only mark the *future* cancelled (done) so deref
# raises and realized?/future-done?/future-cancelled? reflect it. Returns false
@ -2755,9 +2753,7 @@
"deliver" core-deliver
"future-call" core-future-call
"future?" core-future?
"future-done?" core-future-done?
"future-cancel" core-future-cancel
"future-cancelled?" core-future-cancelled?
"tagged-literal" core-tagged-literal
"ensure-reduced" core-ensure-reduced
"unreduced" core-unreduced