Last active
August 29, 2015 14:07
-
-
Save joshbedo/0a9fe4260201b569d33d to your computer and use it in GitHub Desktop.
jQuery's not so great API for promises
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
post: (endpoint, params = {})-> | |
defer = $.Deferred() | |
$.when( | |
@requestChallenge() | |
).then( | |
(res) => | |
@authChallenge(res) | |
, | |
(res) => | |
defer.reject(res) | |
).then( | |
(res) => | |
@_post endpoint, (_.extend {}, res, params) | |
, | |
(res) => | |
defer.reject(res) | |
).then( | |
(res)-> | |
defer.resolve(res) | |
, | |
(res)-> | |
defer.reject(res) | |
) | |
return defer.promise() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment