Skip to content

Instantly share code, notes, and snippets.

@jamesmintram
Created July 29, 2015 17:56
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 jamesmintram/232849395526ce9ca581 to your computer and use it in GitHub Desktop.
Save jamesmintram/232849395526ce9ca581 to your computer and use it in GitHub Desktop.
Is there a better way to write this?
(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"))
""))
@holyjak
Copy link

holyjak commented Jul 31, 2015

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 ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment