Public Vars

Back

compare-and-set! (clj)

(source)

function

(compare-and-set! atom oldval newval)
Atomically sets the value of atom to newval if and only if the current value of the atom is identical to oldval. Returns true if set happened, else false

Examples

typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
  "Type annotations for the base Clojure distribution."
  #?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
  (:require [clojure.core :as cc]
            [typed.clojure :as t]
            #?(:clj [typed.ann-macros.clojure :as macros])
            #?(:clj typed.ann.clojure.jvm) ;; jvm annotations
            #?(:clj clojure.core.typed))
  #?(:clj
     (:import (clojure.lang PersistentHashSet PersistentList
                            APersistentMap #_IPersistentCollection
                            #_ITransientSet
                            IRef)
              (java.util Comparator Collection))))

cc/reset! (t/All [x] [(t/Atom x) x :-> x])
cc/swap! (t/All [x b :..] [(t/Atom x) [x b :.. b :-> x] b :.. b :-> x])
#?@(:cljs [] :default [
cc/reset-vals! (t/All [x] [(t/Atom x) x :-> '[x x]])
cc/swap-vals! (t/All [x b :..] [(t/Atom x) [x b :.. b :-> x] b :.. b :-> '[x x]])
])
cc/vreset! (t/All [x] [(t/Volatile x) x :-> x])
cc/volatile? (t/Pred t/AnyVolatile)
cc/compare-and-set! (t/All [x] [(t/Atom x) t/Any x :-> t/Bool])