Created
July 29, 2015 17:56
-
-
Save jamesmintram/232849395526ce9ca581 to your computer and use it in GitHub Desktop.
Is there a better way to write this?
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
(defroutes thin-app | |
(GET "/" [] "") | |
(POST "/foo" req | |
(if (= [:failed :default] (async/alts!! [[event-sink (slurp (:body req))]] :default :failed)) | |
(println "FULL - 503") | |
(println "OK - 201")) | |
"")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, you're asking about line #4, I suppose? So you are putting the body onto the event-sink channel but don't want to block if it is full yet find it out and notify the client.
Perhaps the 1st question to ask here is do I really need/want async at this point, isn't it an overkill? Especially since you have here essentially a request-reply communication, not an async one?
I don't really see a better way than
if
. After all you are deciding between two different cases ...