const fs = require('fs');
function writeFile() {
fs.writeFile('a.txt', 'hello', { flag: 'a' }, err => {
if (err) return console.log(err);
console.log('ok');
});
}
function name() {
writeFile();
while (1) { }
}
name();
- 创建并写入'hello',打印'ok'
- 创建并写入'hello',没有打印
- 创建但没有写入'hello',没有打印
- 不创建,没有打印
各位看看会是哪种情况呢?为什么?
创建但没有写入'hello',没有打印
马上创建,等待异步写入,
回到主流程,while(1) 无限循环,然后就死了。