-
-
Save elfenlaid/3a1391c585a31c8a6346 to your computer and use it in GitHub Desktop.
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
(defn waitForFuture [timeout & refs] (doseq [r refs] (deref r timeout nil))) | |
(def phrase (ref "hello")) | |
(waitForFuture 1 | |
(future (dosync (println "will rename phrase") (Thread/sleep 1000) (ref-set phrase "world"))) | |
(future (dosync (println @phrase) (Thread/sleep 2000) (println @phrase)))) | |
;; What I get here | |
;; > will rename phrase -- first future kicks in | |
;; > hello -- second future kicks in | |
;; > nil | |
;; > world -- aaand second future redone it's stuff cause ref was changed, | |
;; > world | |
;; Now, when I eval the same thing, but only after resetting thing with dosync | |
(dosync (ref-set phrase "hello")) | |
(waitForFuture 1 | |
(future (dosync (println "will rename phrase") (Thread/sleep 1000) (ref-set phrase "world"))) | |
(future (dosync (println @phrase) (Thread/sleep 2000) (println @phrase)))) | |
;; What I get is next: | |
;; > will rename phrase -- first future kicks in | |
;; > hello -- second future kicks in | |
;; > nil | |
;; > hello -- wowowow, wait a second, isn't ref phrase was renamed in first future? | |
;; -- shouldn't STM do it STMish things and retry here? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment