Skip to content

Instantly share code, notes, and snippets.

@saibotsivad
Last active August 29, 2015 14:18
Show Gist options
  • Save saibotsivad/d7283560cc304130d70f to your computer and use it in GitHub Desktop.
Save saibotsivad/d7283560cc304130d70f to your computer and use it in GitHub Desktop.
Chain of promises split apart and recombined
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)
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