我有一個功能,將根據數據庫中的文件處理引腳的開關狀態。這個函數使用了很多的庫,我認爲其中的一個導致了棄用(基於我的代碼片段下面包括的棄用跟蹤,我認爲它是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