使用 context.done() 后我会得到 Promise 吗?
Will I get a Promise once use context.done()?
我遵循了 MS 编写 Azure 函数的所有指南。不知何故必须使用 .done()
否则客户端(邮递员)将看不到任何 returns:
module.exports = async function(context)
{
...
const result = await aPromise().catch((bad)=>
{
context.res = {status: 401, body: "bad"};
context.done(); // needed so client can get the above res
});
}
这是否意味着 return 不是 Promise
?
如果你的函数是同步,它不会return一个Promise,所以你必须通过context
对象,因为正确使用需要调用 context.done。
// 你应该包括上下文,其他参数是可选的
module.exports = function(context, yourTrigger, yourInput) {
// your function code
context.done();
};
如果你的函数是async function
. You don’t need to call the context.text. While your async function declaration of the Functions runtime, you do not need to explicitly call the context.done
回调,表示你的函数已经完成。
从功能版本2.x
开始适用。如果您使用的是函数版本 1.x
,则需要调用 context.done 回调。
module.exports = async function (context) {
context.log(‘your log');
};
注:
编写 异步函数时,无需显式调用 done
隐式调用 done
回调。
参考here了解更多信息
我遵循了 MS 编写 Azure 函数的所有指南。不知何故必须使用 .done()
否则客户端(邮递员)将看不到任何 returns:
module.exports = async function(context)
{
...
const result = await aPromise().catch((bad)=>
{
context.res = {status: 401, body: "bad"};
context.done(); // needed so client can get the above res
});
}
这是否意味着 return 不是 Promise
?
如果你的函数是同步,它不会return一个Promise,所以你必须通过context
对象,因为正确使用需要调用 context.done。
// 你应该包括上下文,其他参数是可选的
module.exports = function(context, yourTrigger, yourInput) {
// your function code
context.done();
};
如果你的函数是async function
. You don’t need to call the context.text. While your async function declaration of the Functions runtime, you do not need to explicitly call the context.done
回调,表示你的函数已经完成。
从功能版本2.x
开始适用。如果您使用的是函数版本 1.x
,则需要调用 context.done 回调。
module.exports = async function (context) {
context.log(‘your log');
};
注:
编写 异步函数时,无需显式调用 done
隐式调用 done
回调。
参考here了解更多信息