Experimental. Adds a watcher to an agent/atom/var/ref reference. The watcher must be an Agent, and the action a function of the agent's state and one additional arg, the reference. Whenever the reference's state changes, any registered watchers will have their actions sent. send-type must be one of :send or :send-off. The actions will be sent after the reference's state is changed. Var watchers are triggered only by root binding changes, not thread-local set!s
; clojure/core.clj:1223 (defn add-watcher [#^clojure.lang.IRef reference send-type watcher-agent action-fn] (add-watch reference watcher-agent (fn [watcher-agent reference old-state new-state] (when-not (identical? old-state new-state) ((if (= send-type :send-off) send-off send) watcher-agent action-fn reference)))))
Copyright (c) Rich Hickey. All rights reserved.
The use and distribution terms for this software are covered by the Eclipse Public License 1.0, which can be found in the file epl-v10.html at the root of this distribution. By using this software in any fashion, you are agreeing to be bound by the terms of this license. You must not remove this notice, or any other, from this software.