我有一个小脚本,运行时出错,nodejs 0.xx.xx直到nodejs6。升级到8或更高版本后,我收到错误消息:“不建议使用不带回调的异步函数。”但是我的意思是我阻碍了回调。
使用脚本将配置文件向下写入Linux系统,并在完成写入后通过tcp消息通知服务器。
writefilesync_wcb(configpath, configfile, 'NEWCONFIG!', callbackDummy );
function writefilesync(filepath, configstring, tcpmsg, callback){
if ( configstring.length > 1) {
try {
var fd = fs.openSync(filepath, 'r');
fs.writeFile(filepath, configstring, (error) => {
if (error) {
throw error;
console.log("# [ERROR] filemgr::writefilesync_wcb error: " + error);
} else {
console.log("# FileWriting was successful | writefilesync_wcb -> TCP");
}
fs.fsync(fd, callback(TCPMessage));
});
}
catch (error) {
}
return 'success';
} else {
console.log("# [ERROR] String Length: " + configstring.length );
}
}
function callbackAnswer (msg) {
console.log ("Callback-repclacement: " + msg);
}
我不理解的是,为什么nodejs <6没有错误,现在我犯了错误。我注意到writefile现在需要一个回调函数。 problem
谢谢