Last active
August 29, 2015 14:18
-
-
Save saibotsivad/d7283560cc304130d70f to your computer and use it in GitHub Desktop.
Chain of promises split apart and recombined
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
Promise.all(getSomePromises) | |
.then(doSomeAction) | |
.then(doSomeOtherAction) | |
.then(function(data) { | |
return Promise.all([ | |
Promise.all(data.filter(subsetOne).map(turnIntoPromises)) | |
.then(doActionOne) | |
.then(doActionTwo), | |
Promise.all(data.filter(subsetTwo).map(turnIntoPromises)) | |
.then(doActionThree) | |
.then(doActionFour) | |
]) | |
}) | |
.then(doSomethingWithCombined) | |
.then(doFinalThing) | |
.catch(handleTheErrors) |
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
Promise.all([ | |
listAllFolderFiles(options.fileFolder).then(filePathsToStats(options.fileFolder)), | |
mostRecentBackup(options.backupFolder).then(listAllFolderFiles).then(filePathsToStats(options.backupFolder)) | |
]) | |
.then(pickTheImportantFiles) | |
.then(continueOrThrowError(options)) | |
.then(createDirectoryStructure(options.backupFolder)) | |
.then(function copyOrSymlinkFiles(files) { | |
return Promise.all([ | |
copyFiles(options, files.toCopy), | |
symlinkFiles(options, files.toSymlink) | |
]) | |
}) | |
.catch(function(err) { | |
console.log('ERR',err) | |
reject(err) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment