Last active
August 29, 2015 14:22
-
-
Save joekarl/8616f64da681af94543f to your computer and use it in GitHub Desktop.
Async examples files
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
var async = require('async'); | |
main(); | |
function main() { | |
processFiles(function(err, results){ | |
}); | |
} | |
function processFiles(cb) { | |
var files = []; | |
async.series([ | |
clearAllFiles.bind(null, files), | |
createAllFiles.bind(null, files) | |
], cb); | |
} | |
function clearAllFiles(files, cb) { | |
async.forEach(files, clearSingleFile); | |
var pipeline = files | |
.filter(function(file){ return file.contains(); }) | |
.map(function(file){ | |
// return function (cb){ | |
// clearSingleFile(file, cb) | |
// }; | |
// return async.apply(clearSingleFile, file); | |
return clearSingleFile.bind(null, file); | |
}); | |
async.parallelLimit(pipeline, 5, cb); | |
} | |
function clearSingleFile(file, cb) { | |
fs.writeFile(file, cb); | |
} | |
function createAllFiles(listOfFiles, cb) { | |
var pipeline = files.map(function(file){ | |
// return function (cb){ | |
// createSingleFile(file, cb) | |
// }; | |
// return async.apply(createSingleFile, file); | |
return createSingleFile.bind(null, file); | |
}); | |
async.parallel(pipeline, cb); | |
} | |
function createSingleFile(file, cb) { | |
} | |
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
https://github.com/joekarl/fastsync/blob/master/fastsync.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment