Created
April 4, 2017 09:04
-
-
Save cgrand/be2fcab9c3c2cd8e0d0a1f490696a05b to your computer and use it in GitHub Desktop.
Did you know? #clojure
This file contains hidden or 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