Last active
October 22, 2018 15:09
-
-
Save marcomorain/5a479d348abe430f17fcc513ee503150 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 future-call [f] | |
;; Before we start the future grab a copy of the current stack | |
(let [stack (.getStackTrace (Exception.))] | |
(future | |
(try | |
(f) | |
(catch Exception e | |
;; An exception thrown from a future has a stack that does not | |
;; include the outer stack trace. We can fix this by appending | |
;; the stack trace we captured above into the caught exception. | |
(.setStackTrace e (into-array | |
StackTraceElement | |
(concat (.getStackTrace e) stack))) | |
(throw e)))))) | |
(defmacro future | |
[& body] | |
`(future-call (fn [] ~@body))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment