Created
March 14, 2014 12:38
-
-
Save katox/9546903 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
(defmacro bg | |
"Runs the body in a background thread. | |
Creates two vars, one named bg<N> and the other bg<N>'. | |
The first will eventually contain the result of the computation, | |
or any exception that is thrown. | |
The second is a map that prints with status & runtime information. | |
Returns the name of the first var." | |
[& body] | |
(let [base (str "bg" (swap! bg-id-counter inc)) | |
sym (symbol base) | |
sym' (symbol (str base \'))] | |
`(do (println "Starting background task" '~sym) | |
(def ~sym) | |
(def ~sym') | |
(run-and-report (var ~sym) (var ~sym') '~sym (fn [] ~@body)) | |
'~sym))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment