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:
parent
a9403e26b0
commit
790f54d2b3
2 changed files with 10 additions and 6 deletions
|
|
@ -293,3 +293,11 @@
|
||||||
(jolt.host/ref-put! vol :val newval) newval)
|
(jolt.host/ref-put! vol :val newval) newval)
|
||||||
(defn vswap! [vol f & args]
|
(defn vswap! [vol f & args]
|
||||||
(vreset! vol (apply f (get vol :val) 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))))
|
||||||
|
|
|
||||||
|
|
@ -1904,10 +1904,8 @@
|
||||||
(def res (fut :res))
|
(def res (fut :res))
|
||||||
(if (= :error (in res 0)) (error (in res 1)) (in res 1)))
|
(if (= :error (in res 0)) (error (in res 1)) (in res 1)))
|
||||||
|
|
||||||
(defn core-future-done? [x]
|
# future-done? / future-cancelled? now live in the Clojure collection tier (pure
|
||||||
(if (core-future? x) (truthy? (x :cached))
|
# reads of :cached/:cancelled). core-future? stays — deref/future-cancel call it.
|
||||||
(error "future-done? requires a future")))
|
|
||||||
(defn core-future-cancelled? [x] (and (core-future? x) (truthy? (x :cancelled))))
|
|
||||||
# Janet OS threads can't be interrupted, so the worker still runs to completion
|
# 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
|
# in the background; we can only mark the *future* cancelled (done) so deref
|
||||||
# raises and realized?/future-done?/future-cancelled? reflect it. Returns false
|
# raises and realized?/future-done?/future-cancelled? reflect it. Returns false
|
||||||
|
|
@ -2755,9 +2753,7 @@
|
||||||
"deliver" core-deliver
|
"deliver" core-deliver
|
||||||
"future-call" core-future-call
|
"future-call" core-future-call
|
||||||
"future?" core-future?
|
"future?" core-future?
|
||||||
"future-done?" core-future-done?
|
|
||||||
"future-cancel" core-future-cancel
|
"future-cancel" core-future-cancel
|
||||||
"future-cancelled?" core-future-cancelled?
|
|
||||||
"tagged-literal" core-tagged-literal
|
"tagged-literal" core-tagged-literal
|
||||||
"ensure-reduced" core-ensure-reduced
|
"ensure-reduced" core-ensure-reduced
|
||||||
"unreduced" core-unreduced
|
"unreduced" core-unreduced
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue