我有一个功能,将根据数据库中的文件处理引脚的开关状态。这个函数使用了很多的库,我认为其中的一个导致了弃用(基于我的代码片段下面包括的弃用跟踪,我认为它是OnOff Gpio Library for Raspberry PI)。哪个功能导致了弃用?回滚Node的更新会有什么不利之处?我真的很想听到这方面的一些意见,提前谢谢。“不鼓励调用异步函数”。但有回电
MongoClient.connect(url, function (err, db) {
if (err) {
console.log('Unable to connect to the mongoDB server. Error:', err);
} else {
var collection = db.collection('re');//change as needed
collection.findAndModify(
{"restart":"sensor","value":false},
{},
{"$set":{"value":true}},
{},
function(err,result){
if(err){
throw err;
}
else{
console.log(result);
if(result.value!=null){
spin.write(0);
setTimeout(function() {
spin.write(1);
},10000);
}
else{
console.log("Sensor should stay on");
spin.write(1);
}
}
});
}
db.close();
});
(节点:10503)DeprecationWarning:调用异步函数 而不回调已被弃用。
在maybeCallback(fs.js:98:42)
在Object.fs.write(fs.js:703:16)
在Gpio.write(/家/ PI/node_modules/onoff/onoff.js:190:6)
at Object。 (/家/ PI /本地OPIO /最终:16:6)
在Module._compile(module.js:571:32)
在Object.Module._extensions..js(module.js :580:10)
在Module.load(module.js:488:32)
在tryModuleLoad(module.js:447:12)
在Function.Module._load(模块。 js:439:3)
at Module.runMain(module.js:605 :10)
在运行(bootstrap_node.js:422:7)
在启动时(bootstrap_node.js:143:9)
在bootstrap_node.js:537:3
看起来像'spin.write'是罪魁祸首。 – 4castle
只是通过'布尔'作为回调,如果你不关心结果。 – dandavis