Created
January 21, 2013 14:36
-
-
Save yuanmai/4586501 to your computer and use it in GitHub Desktop.
deliver / promise, look ma no callbacks
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
| (defn check-item [p id] | |
| (if-let [item (find-item id)] | |
| (do (deliver p item) | |
| nil) | |
| (status 404 "Item not found"))) | |
| (defn check-access [item] | |
| (when-not (can-user-access? item) | |
| (status 403 "Go away"))) | |
| (let [itemp (promise)] | |
| (or (check-item itemp id) | |
| (check-access @itemp) | |
| (do | |
| (other-stuff-with @itemp) | |
| (redirect "/some-where")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment