为什么我的 Firebase 控制台总是出现“Promise {待处理}”?
我很确定我正确地使用了带有“.then”的 promise 概念。我的函数出了什么问题? (与亚历山大主教编辑)
exports.GenerateLiveGameIfAllPlayerReady = functions.database.ref("games/lobby/{pushId}/playerList/{playerId}").onUpdate(event => {
//Get the object of the game then put it in the Live games node
const transfertNewLiveGame = event.data.ref.parent.parent.once('value').then(snap => {
return snap.val();
}).then(() => {
console.log(transfertNewLiveGame);
console.log(event.params.pushId);
return admin.database().ref('games/live').update({
[event.params.pushId]: transfertNewLiveGame
});
})
最佳答案
正如您所说,触发函数需要Promise
,但您缺少return
。所以你的代码应该是这样的。
exports.GenerateLiveGameIfAllPlayerReady = functions.database.ref("games/lobby/{pushId}/playerList/{playerId}").onUpdate(event => {
return event.data.ref.parent.parent.once('value', function(snap) {
return admin.database().ref('games/live').update({
[event.params.pushId]: snap.val()
});
});
关于node.js - Firebase云功能同步nodejs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49099055/