Created
April 4, 2017 09:04
Star
You must be signed in to star a gist
Did you know? #clojure
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
;; did you know that binding conveying is not immutable but read-only? (the future sees updates performed by the original thread) | |
=> (with-local-vars [a 1] | |
(future (Thread/sleep 1000) (prn 'future @a)) | |
(var-set a 2)) | |
2 | |
future 2 | |
;; you have to push new bindings to isolate: | |
=> (with-local-vars [a 1] | |
(with-bindings {a @a} | |
(future (Thread/sleep 1000) (prn 'future @a))) | |
(var-set a 2)) | |
2 | |
future 1 | |
;; but it's a var-by-var isolation: | |
=> (with-local-vars [a 1 | |
b 'one] | |
(with-bindings {a @a} | |
(future (Thread/sleep 1000) (prn 'future @b))) | |
(var-set b 'two)) | |
two | |
future two | |
;; to completely isolate from upstream changes, one has to do: | |
=> (with-local-vars [a 1 | |
b 'one] | |
(with-bindings (get-thread-bindings) | |
(future (Thread/sleep 1000) (prn 'future @b))) | |
(var-set b 'two)) | |
two | |
future one |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment