Skip to content

Instantly share code, notes, and snippets.

@alexbeletsky
Created March 22, 2014 13:23
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexbeletsky/9707023 to your computer and use it in GitHub Desktop.
Save alexbeletsky/9707023 to your computer and use it in GitHub Desktop.
Callbacks + Async
async.waterfall([
download,
process,
upload
], function (err, results) {
if (err) {
return console.error('processing failed, error: ', err);
}
console.log('processing completed, results: ', results);
});
function download(callback) {
ftp.download(url, function (err, stream) {
// ... check errors and read stream, callback then ready
callback(null, file);
})
}
function process(file, callback) {
// read file, read data from files..
callback(null, file, stats);
}
function upload(file, stats, callback) {
ftp.upload(file, function (err) {
// ... check errors and stuff
callback(null, {file: file.name, stats: stats});
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment