Skip to content

Instantly share code, notes, and snippets.

@noisesmith
Created January 20, 2016 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noisesmith/653e2280be728ab3909f to your computer and use it in GitHub Desktop.
Save noisesmith/653e2280be728ab3909f to your computer and use it in GitHub Desktop.
does add-watch run a watcher on a ref in a transaction?
kingfisher.core=> (def bar (ref {}))
#'kingfisher.core/bar
kingfisher.core=> (def bar (ref 0))
#'kingfisher.core/bar
kingfisher.core=> (def foo (ref 1))
#'kingfisher.core/foo
kingfisher.core=> (add-watch foo :update (fn [_ _ _ new] (alter bar + new)))
#object[clojure.lang.Ref 0x37670b96 {:status :ready, :val 1}]
kingfisher.core=> (dosync (alter foo inc))
IllegalStateException No transaction running clojure.lang.LockingTransaction.getEx (LockingTransaction.java:208)
kingfisher.core=> (add-watch foo :update (fn [_ _ _ new] (dosync (alter bar + new))))
#object[clojure.lang.Ref 0x37670b96 {:status :ready, :val 2}]
kingfisher.core=> (dosync (alter foo inc))
3
kingfisher.core=> bar
#object[clojure.lang.Ref 0x27132209 {:status :ready, :val 3}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment