Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
readFile("filename.txt", function(err, data) {
console.log("5 seconds have elapsed");
if (err) { return; }
readFile("otherfile.txt", function(err, data) {
console.log("10 seconds have elapsed");
if (err) { return; }
writeFileToNetwork(data, function(err, response) {
if (err) { return; }
console.log("complete");
});
});
});
readFile("otherfile.txt", function(err, data) {
console.log(data);
});
readFile("filename.txt")
.then(function (data) {
console.log(data);
return readFile("otherfile.txt");
})
.then(function (otherData) {
console.log(otherData);
return writeFileToNetwork(otherData);
})
.then(function (response) {
console.log("complete");
})
.catch(function (err) {
console.error(err);
});
// var data = readFile("filename.txt"); - 5 secs
// var otherFile = readFile("otherfile.txt"); - 5 secs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.