Created
March 22, 2014 13:23
-
-
Save alexbeletsky/9707023 to your computer and use it in GitHub Desktop.
Callbacks + Async
This file contains hidden or 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
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