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