Last active
December 17, 2015 09:08
-
-
Save phadej/5585042 to your computer and use it in GitHub Desktop.
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
function fin(promise, body) { | |
return promise.then(function (res) { | |
return as(body()).then(function() { | |
return res; | |
}); | |
}, function(function (err) { | |
// if body throws something other, that will override current error | |
return as(body()).then(function() { | |
throw err; | |
}); | |
}); | |
} | |
// use like | |
fin(openStuff().then(asyncStuff), function(res) { | |
return closeStuff(); | |
}) | |
.then(doOtherStuff); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from https://github.com/kriskowal/q