Created
January 20, 2016 00:25
-
-
Save noisesmith/653e2280be728ab3909f to your computer and use it in GitHub Desktop.
does add-watch run a watcher on a ref in a transaction?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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