Skip to content

Instantly share code, notes, and snippets.

@marcomorain
Last active October 22, 2018 15:09
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 marcomorain/5a479d348abe430f17fcc513ee503150 to your computer and use it in GitHub Desktop.
Save marcomorain/5a479d348abe430f17fcc513ee503150 to your computer and use it in GitHub Desktop.
(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