什么时候使用serTimeout()?
/*
* 假设write_log()花费1秒,那么read_data()得多等1秒才能返回,
* 然后show_data()才能把数据展示给用户。但是用户根本不关心你的日志,
* 让用户为此多等1秒其实毫无意义,这种场景就可以用setTimeout(callback,0)来调用write_log
* 让read_data()立刻返回并将数据展示给用户。node里可以用nextTick,会更快一些。
*/
function read_data(){
read_file();
write_log();
//setTimeout(write_log,0);
}
read_data();
show_data();