Created
November 29, 2016 18:56
-
-
Save christianromney/285b1c3254cd4022d8226a8857345e0a to your computer and use it in GitHub Desktop.
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
(defmacro <!? | |
"Exception-aware parking take. If a Throwable is returned | |
from the channel, it is re-thrown." | |
[c] | |
`(let [v# (<! ~c)] | |
(if (instance? Throwable v#) | |
(throw v#) | |
v#))) | |
(defmacro <!!? | |
"Exception-aware blocking take. If a Throwable is returned | |
from the channel, it is rethrown." | |
[c] | |
`(let [v# (<!! ~c)] | |
(if (instance? Throwable v#) | |
(throw v#) | |
v#))) | |
(defmacro go-try | |
"Tries to execute the body in a go block. If an exception is thrown, | |
it is placed on the channel." | |
[& body] | |
`(go | |
(try | |
~@body | |
(catch Throwable t# | |
t#)))) | |
(defmacro thread-try | |
"Tries to execute the body in a thread block. If an exception is thrown, | |
it is placed on the channel." | |
[& body] | |
`(thread | |
(try | |
~@body | |
(catch Throwable t# | |
t#)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment