【发布时间】:2020-11-27 12:24:33
【问题描述】:
我是 GCF 和 Javascript 异步的新手,一直在努力解决这个问题。我最初执行 fetch 调用,然后将该响应作为参数传递给第二个函数,然后该函数也执行单独的 fetch 调用。
在第二个函数期间,我的空初始化 json 获取添加到其中的属性,当该函数完成时,我想通知 exports.helloHttp 然后执行 res.end 并终止。
我尝试链接一个额外的空then(),但它似乎不起作用。
我的代码:
var json = {}; // <- gets properties added to it during secondFunction()
exports.helloHttp = (req, res) => {
fetch("firstfetchurl.com",requestOptions)
.then(result => result.json())
.then(response => {
// next take the result and create a new product
return secondFunction(response);
})
.catch(error => console.log('error', error));
// res.end(JSON.stringify(json)); <- this is what I want my cloud function to output, but only after secondFunction completes
};
【问题讨论】:
-
你不能给
secondFunction()打个电话吗?
标签: javascript asynchronous promise async-await google-cloud-functions