Skip to content

Instantly share code, notes, and snippets.

@hugoduncan
Created September 8, 2010 15:00
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 hugoduncan/570249 to your computer and use it in GitHub Desktop.
Save hugoduncan/570249 to your computer and use it in GitHub Desktop.
thread-local values
(defmacro thread-local
"Create a thread local, initialised by body. The value can be obtained by
dereferncing the the thread-local with deref/@."
[& body]
`(proxy [java.lang.ThreadLocal clojure.lang.IDeref] []
(~'initialValue
[] ~@body)
(~'deref
[] (.get ~'this))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment