恐怕这可能是我完全误解异步工作方式的一个简单案例。我正在使用 NPM 模块 azure-storage。我遇到的问题是该函数似乎在执行回调之前完成。更糟糕的是,Azure Functions 有一些神奇之处,你可以通过设置context.res属性来“完成”你的函数。他们曾经要求你打电话,context.done()但有些东西从 v1 变成了 v2,现在我想不再是那样了。但是,即使是这种情况,函数也会在回调执行之前结束。更糟糕的是,我的实体甚至没有被插入,但我不知道为什么。var azure = require('azure-storage');var validate = require('validate.js');var constraints = { PartitionKey: { presence: true, email: true }, description: { presence: true }, dueDate: { presence: true }};module.exports = async function (context, req) { context.log('JavaScript HTTP trigger function processed a request.'); if (!(req.body && req.body.PartitionKey) || !(req.body && req.body.description) || !(req.body && req.body.dueDate)) { context.res = { status: 400, body: "Please pass a name on the query string or in the request body" }; } var tableSvc = azure.createTableService(); var input = req.body; context.log('PartitionKey: ' + input.PartitionKey); context.log('description: ' + input.description); context.log('dueDate: ' + input.dueDate); context.log(validate({ PartitionKey: input.PartitionKey }, constraints)); context.log(validate({ description: input.description }, constraints)); context.log(validate({ dueDate: input.dueDate }, constraints)); var entGen = azure.TableUtilities.entityGenerator; var task = { PartitionKey: entGen.String(input.PartitionKey), RowKey: entGen.String('1'), description: entGen.String(input.description), dueDate: entGen.DateTime(input.dueDate) }; }; } });};
添加回答
举报
0/150
提交
取消