gpt4 book ai didi

node.js - Firebase云功能同步nodejs

转载 作者:太空宇宙 更新时间:2023-11-03 23:00:37 25 4
gpt4 key购买 nike

为什么我的 Firebase 控制台总是出现“Promise {待处理}”?

enter image description here我很确定我正确地使用了带有“.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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com