node.js - 在 Azure 函数中调用无等待函数
问题描述
可以在 Azure Function 中调用异步函数而不等待该函数吗?
尽管我必须在这里简化代码,但这实际上对我有用。getData() 在 runInBackground() 之前终止。几秒钟后,runInBackground 完成。
但是,它在 MS Azure 文档中实现等待,但不确定是否涵盖了这种情况。鉴于 runInBackground 的用例,这是可以接受的吗?这个实现可能会出现什么问题?
处理程序天蓝色函数
export const getData: AzureFunction = async function (
context: Context,
req: HttpRequest,
): Promise<void> {
try {
// really need to wait for this
const data = await service.getData(...);
// no need to wait, no await
runInBackground();
context.res = handleResp(data);
} catch (e) {
context.res = handleErr(e);
}
};
一个旨在单独运行的功能(有点像一劳永逸)。无需知道结果。
export const runInBackground = async () => {
const url = `https://externalapi/call`;
try {
await axios.post(url, {});
} catch (error) {
console.log(error.response);
}
};
编辑:在 getData() 成功返回响应后,runInBackground() 进程是否有可能被终止/删除?我实际上对此进行了测试,没有问题——它继续进行。我只是想知道这是一种成功还是失败。如果有这方面的文件。
解决方案
推荐阅读
- oracle-cloud-infrastructure - 默认用户的 Oracle Cloud shell 密码是什么
- android - 如何根据约束布局中的内容创建视图?
- jquery - 在 asp.net 核心中使用 jQuery 动态创建选择并从数据库中添加选择选项
- c++ - C++ 的 UML 序列图:对象的功能有哪些生命线?
- php - 如何自动处理表单中的所有字段并将它们传递给 php?
- javascript - JSX 花括号内的 if 和 else if 语句
- elasticsearch - 弹性搜索仅根据其字段值对某些文档应用提升
- kubernetes-pod - Pod 崩溃时如何恢复用户数据
- python - Kivy call SELF method from another class
- python - 如何绘制图像中文本的像素值直方图?