为什么我总是进入我的firebase控制台“Promise {pending}”?
我很确定我正确地使用了承诺概念和“.then”..我的功能有什么问题? (与Alexandr Biship一起编辑)
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()
});
});