Public Vars

Back

remove-watch (clj)

(source)

function

(remove-watch reference key)
Removes a watch (set by add-watch) from a reference

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/add-watch (t/All [x [a :< (#?(:clj IRef :cljs t/Atom) x)]]
                    (t/IFn
                      ; this arity remembers the type of reference we pass to the function
                      [a t/Any [t/Any a x x :-> t/Any] :-> t/Any]
                      ; if the above cannot be inferred, 
                      [(#?(:clj IRef :cljs t/Atom) x) t/Any [t/Any (#?(:clj IRef :cljs t/Atom) x) x x :-> t/Any] :-> t/Any]))
cc/remove-watch (t/All [x] [(#?(:clj IRef :cljs t/Atom) x) t/Any :-> t/Any])
logicblocks/salutem
(ns salutem.core.maintenance-test
  (:require
   [clojure.test :refer :all]
   [clojure.core.async :as async]

    (try
      (loop [attempts 1]
        (if @updated?
          (is (= @registry-store
                (registry/with-cached-result registry check-name result)))
          (if (< attempts 5)
            (do
              (async/<!! (async/timeout 25))
              (recur (inc attempts)))
            (throw (ex-info "Registry was not updated before timeout."
                     {:registry @registry-store})))))
      (finally
        (remove-watch registry-store :watcher)
        (async/close! result-channel)))))

    (try
      (loop [attempts 1]
        (if (= @updated-count 3)
          (is (= @registry-store
                (-> registry
                  (registry/with-cached-result check-1-name result-1)
                  (registry/with-cached-result check-2-name result-2)
                  (registry/with-cached-result check-3-name result-3))))
          (if (< attempts 5)
            (do
              (async/<!! (async/timeout 25))
              (recur (inc attempts)))
            (throw (ex-info "Registry was not updated before timeout."
                     {:registry @registry-store})))))
      (finally
        (remove-watch registry-store :watcher)
        (async/close! result-channel)))))