Created
June 29, 2017 08:47
-
-
Save timaschew/8aeab1b41760396ab26d61e5ed22d02e to your computer and use it in GitHub Desktop.
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
const fs = require('fs') | |
function async1(callback) { | |
console.log('1') | |
setTimeout(function() { | |
console.log('2') | |
if (Math.random() > 0.5) { | |
return callback(new Error('boom')) | |
} | |
return callback(null, 'config.txt') | |
}, 100) | |
console.log('4') | |
return 5 // useless | |
} | |
function async2(fileName, options, callback) { | |
fs.readFile(fileName, options, callback) | |
} | |
async1(function(err, value) { | |
if (err) { | |
return console.error(err) | |
} | |
return async2(value, {encoding: 'utf8'}, function(err, result) { | |
if (err) { | |
return console.log(err) | |
} | |
console.log(result.toString()) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment