我已经看到了这个问题,但没有好的答案。我可以理解问题是什么,但似乎无法找出如何解决它。这是我的功能:
<body class="my_home_template">
所以我明白我的回程是在一切运行完毕之前被调用的。我该如何解决这个问题?当然,我的返回是一个空数组,我从firebase得到错误:错误:函数崩溃了请求范围函数调用被中断。
谢谢!
答案 0 :(得分:1)
您必须使用从此处返回的承诺:
db.collection('games')
.where('accountId', '==', accountId)
.get()
这是一个异步调用,它会立即返回一个在工作完成时解析的promise。
您需要使用该承诺在合适的时间发送回复:
const proimise = db.collection('games')
.where('accountId', '==', accountId)
.get()
promise.then(snapshot => {
// work with the document snapshot here, and send your response
})
.catch(error => {
// deal with any errors if necessary.
response.status(500).send(error)
})
您发送响应的方式似乎没问题,您只需等待提取完成。