node.js - 读取 Firebase 数据会阻止异步方法解析
问题描述
我正在尝试编写从 Firebase 读取的 Alexa 技能
我处于使用 Alexa 测试控制台时调用 NodeJS 方法的位置,但是如果我添加代码以从 Firebase 检索数据,则该方法会挂起,直到 lambda 超时
const HelloWorldIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'plantsIntent';
},
async handle(handlerInput) {
const snapshot = (await db.collection('plants').get()).data();
const names = snapshot.docs.map(doc => doc.data().name);
const speakOutput = 'Get yourself some cool plants like' + names.join(' and ');
console.log(speakOutput);
var response = handlerInput.responseBuilder
.speak(speakOutput)
//.reprompt('add a reprompt if you want to keep the session open for the user to respond')
.getResponse();
console.log(response);
return response;
}
};
当我运行此代码时,我将speakOutput
字符串和response
对象输出都放入日志中,因此我知道代码正在设法做到这一点
我怀疑这与 Firebase 有关,就好像我删除了db.collection('plants').get()
代码段(和相关变量)然后代码运行完成
我怀疑这与方法未返回而不是发生异常有关,因为response
在工作版本(没有 Firebase .get()
)和非工作版本中的输出是相同的
任何帮助,将不胜感激!
解决方案
推荐阅读
- java - 从 valueof 枚举类返回默认值
- javascript - Babel 类型转换 - 在运算符周围添加空间。如何绕过?
- assembly - 我在理解 ARM Assembly 中的 ED 堆栈时遇到问题
- c - Linux shell 分配。Execvp 无法执行命令
- javascript - Javascript for 循环只创建一个孩子
- python - pip install pyaudio gcc 错误“函数声明不是原型”
- python - 将文本文件转换为带有列的 csv
- vba - 引用表单失败且没有错误消息
- javascript - 无法多次等待 Axios 调用
- c - 使 C 中的两个对象更加面向对象