Jaa*_*and 6 javascript async-await firebase google-cloud-functions
因此,我很高兴一直在使用async / await,因为Firebase Cloud Functions支持节点8。我正在努力做一件事情。使用可调用函数时,系统会告知您必须在函数中返回一个promise,否则它将无法正常工作。使用原始的诺言时,我很清楚如何使用它:
exports.createBankAccount = functions.region('europe-west1').https.onCall((data, context) => {
return promiseMethod().then((result) => {
return nextPromise(result);
}).then((result) => {
return result;
}).catch((err) => {
// handle err
})
});
Run Code Online (Sandbox Code Playgroud)
但是现在,异步等待着,我不确定如何返回这个“承诺链”:
exports.createBankAccount = functions.region('europe-west1').https.onCall(async (data, context) => {
const res1 = await promiseMethod();
const res2 = await nextPromise(res1);
return res2;
// ??? Where to return the promise?
});
Run Code Online (Sandbox Code Playgroud)
有人知道吗
HTTP 函数不返回承诺。他们只是发送结果。您仍然必须正确使用 Promise 才能发送结果,但不需要返回值。HTTP 函数在发送响应时终止。请参阅文档了解更多详细信息:
使用 res.redirect()、res.send() 或 res.end() 终止 HTTP 函数。
| 归档时间: |
|
| 查看次数: |
1963 次 |
| 最近记录: |