【发布时间】:2017-02-27 19:03:02
【问题描述】:
我有一个函数可以根据数据库中的文档处理引脚的开关状态。这个函数使用了很多库,我相信其中一个导致了弃用(基于我在代码 sn-p 下面包含的弃用跟踪,我认为它是用于 Raspberry PI 的 OnOff Gpio 库)。哪个功能导致弃用?回滚 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();
});
(node:10503) DeprecationWarning: 调用异步函数 不推荐使用没有回调的。
在可能回调(fs.js:98:42)
在 Object.fs.write (fs.js:703:16)
在 Gpio.write (/home/pi/node_modules/onoff/onoff.js:190:6)
在对象。 (/home/pi/local-opio/final: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 (module.js:439:3)
在 Module.runMain (module.js:605:10)
运行时 (bootstrap_node.js:422:7)
在启动时 (bootstrap_node.js:143:9)
在 bootstrap_node.js:537:3
【问题讨论】:
-
看来
spin.write是罪魁祸首。 -
如果您不关心结果,只需将
Boolean作为回调传递。
标签: javascript node.js asynchronous raspberry-pi3 deprecation-warning