Last active
June 17, 2016 22:59
-
-
Save kainage/39a52267edd359a284d8069359d3a092 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
# Resolves an arbitrary number of promises in order. Returns the last promise | |
# unresolved (or an empty promise if there were none) for chainability. | |
serialResolver = (promises) -> | |
promise = promises.shift() | |
switch | |
# Promise array was empty to begin with. | |
when promise is undefined | |
$q.when() | |
# For the last promise in the array, return it for chainability. | |
when promises.length is 0 | |
promise | |
# Process a promise serially and call the next one. | |
else | |
promise.then -> | |
serialResolver(promises) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment