异步函数隐式返回promise。因此,没有必要手动执行此操作。这应该很好:
在firebase文档中,他们说在异步操作之后应该返回promise
"要在异步操作后返回数据,请返回promise">
https://firebase.google.com/docs/functions/callable#sending_back_the_result
在示例中,他们使用then在异步操作完成后向客户端返回消息。但是当我使用等待时呢?我可以只返回一个对象吗?还是必须将其包装在承诺中?
const response = await fetch('ttps://sandbox.itunes.apple.com/verifyReceipt', options);
if (response.status === 200)
return {
status: 200,
message: "Subscription verification successfuly!"
}
或
if (response.status === 200)
return Promise.resolve({
status: 200,
message: "Subscription verification successfuly!"
});
const fetchData = async () => {
const response = await fetch('https://sandbox.itunes.apple.com/verifyReceipt', options);
if (response.status === 200)
return {
status: 200,
message: "Subscription verification successfuly!"
}
else
return null
}
实际上,函数fetchData
实际上返回Promise<any>
,因为它被标记为异步