Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript MongoDB Stitch函数是否支持异步/等待定义?_Javascript_Mongodb_Async Await_Mongodb Stitch - Fatal编程技术网

Javascript MongoDB Stitch函数是否支持异步/等待定义?

Javascript MongoDB Stitch函数是否支持异步/等待定义?,javascript,mongodb,async-await,mongodb-stitch,Javascript,Mongodb,Async Await,Mongodb Stitch,MongoDB(Atlas)上的异步函数定义在GUI编辑器上显示警告。包括触发器参考上提供的示例代码 找到的代码可以直接复制到Stitch函数编辑器,并由于async关键字而产生警告 文档中的示例代码 exports = async function (changeEvent) { // Destructure out fields from the change stream event object const { updateDescription, fullDocument }

MongoDB(Atlas)上的异步函数定义在GUI编辑器上显示警告。包括触发器参考上提供的示例代码

找到的代码可以直接复制到Stitch函数编辑器,并由于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是否支持async/await范例,以及我是否应该关注显示的警告。

经过一些测试后,我发现此时
async/await
关键字会导致linter抛出错误和警告。这意味着,对于异步回调,最好单独定义它们,因为这将改进linting。例如,
[].map(async()=>{})
将提示可以解决的错误


运行时执行返回标准异步操作的预期结果。

警告实际上说了什么?毕竟这只是一个警告…大多数人只是说缺少分号。经过一些尝试和错误,我发现
async
关键字后面的分号使它停止显示,但当然,这似乎是因为它的linter搞乱了。嗨,我也有同样的问题,希望摆脱这些警告。请你再详细说明一下怎么修理好好吗?谢谢。简言之,执行工作如期进行。门楣有一个错误的问题。好的,是的,尽管有这些警告,它仍然工作。尽管如此,当使用async/await而不是经典的promises语法时,我的响应时间有了很大的不同(慢了3-4倍)。是吗?我没有遇到这种情况,可能是因为我们从未尝试过纯粹的承诺。如果要推测的话,我假设Javascript运行时在使用async/await语法sugar时做了更好的内部优化