MongoDB(Atlas)Stitch上的异步函数定义在GUI编辑器上显示警告。包括触发器参考中提供的示例代码。
找到的here代码可以直接复制到Stitch Function编辑器中,并且由于async关键字而产生警告。
文档中的示例代码。
exports = async function (changeEvent) {
// Destructure out fields from the change stream event object
const { updateDescription, fullDocument } = changeEvent;
// Check if the shippingLocation field was updated
const updatedFields = Object.keys(updateDescription.updatedFields);
const isNewLocation = updatedFields.some(field =>
field.match(/shippingLocation/)
);
// If the location changed, text the customer the updated location.
if (isNewLocation) {
const { customerId, shippingLocation } = fullDocument;
const twilio = context.services.get("myTwilioService");
const mongodb = context.services.get("mongodb-atlas");
const customers = mongodb.db("store").collection("customers");
const { location } = shippingLocation.pop();
const customer = await customers.findOne({ _id: customer_id })
twilio.send({
to: customer.phoneNumber,
from: context.values.get("ourPhoneNumber"),
body: `Your order has moved! The new location is ${location}.`
});
}
};
我想知道Stitch是否支持异步/等待模式,是否应该关注显示的警告。
答案 0 :(得分:0)
经过一些测试,我发现此时async/await
关键字会导致短毛猫抛出错误和警告。这意味着对于异步回调,最好单独定义它们,因为这样可以改善毛发。 IE浏览器[].map(async () => {})
会提示可以解决的错误。
运行时执行返回标准异步操作所期望的结果。