Sails.js SyntaxError: await is only valid in async function

Sails.js SyntaxError: await is only valid in async function

我是 Sails.js 的新手,但一位客户希望我创建一个调用所有辅助函数的主控制器。这是一个例子:

result = await sails.helpers.user.action(action, req, result);
module.exports = {


  friendlyName: 'User Action',


  description: 'User Action tile.',


  inputs: {
    action: {
        description: 'action of grid',
        required: true,
        type: "string",
      },
      req: {
          description: 'req object posted',
          required: true,
          type: "ref",
      },
      result: {
          description: 'req object posted',
          type: "ref",
          defaultsTo: {},
      },
  },


  exits: {

    success: {
      description: 'All done.',
    },

  },


  fn: async function (inputs) {
    var action = inputs.action;
    var req = inputs.req;
    var result = inputs.result;
    var post = inputs.req;
    user_id = req.me ? req.me.user_id : 0;

当我运行代码时,出现标题中提到的错误。我该如何解决这个错误?

此错误指的是:您的函数必须是异步函数才能使用'wait',只需将async关键字放在函数定义之前即可。

    async function doSomething() {
        result = await sails.helpers.user.action(action, req, result);
    }