From 790f54d2b3d28fdfe5dd7d20727c0ff657dde253 Mon Sep 17 00:00:00 2001 From: Yogthos Date: Sun, 7 Jun 2026 21:41:11 -0400 Subject: [PATCH] =?UTF-8?q?core:=20Phase=204=20=E2=80=94=20move=20future-d?= =?UTF-8?q?one=3F/future-cancelled=3F=20to=20the=20overlay?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- jolt-core/clojure/core/20-coll.clj | 8 ++++++++ src/jolt/core.janet | 8 ++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/jolt-core/clojure/core/20-coll.clj b/jolt-core/clojure/core/20-coll.clj index ebcd446..efd9fdb 100644 --- a/jolt-core/clojure/core/20-coll.clj +++ b/jolt-core/clojure/core/20-coll.clj @@ -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)))) diff --git a/src/jolt/core.janet b/src/jolt/core.janet index c0b2530..676f458 100644 --- a/src/jolt/core.janet +++ b/src/jolt/core.janet @@ -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