node.js - NodeJS : Async/Await Raspberry Pi

标签 node.js asynchronous raspberry-pi async-await raspberry-pi3

我有一些代码在我的日常计算机上完美运行,但在尝试从树莓派(3 型号 B)启动时出现错误。错误如下:

>     setInterval(async function () {
>                 ^^^^^
>     
>     SyntaxError: missing ) after argument list
>         at exports.runInThisContext (vm.js:53:16)
>         at Module._compile (module.js:414:25)
>         at Object.Module._extensions..js (module.js:442:10)
>         at Module.load (module.js:356:32)
>         at Function.Module._load (module.js:311:12)
>         at Function.Module.runMain (module.js:467:10)
>         at startup (node.js:134:18)
>         at node.js:961:3

我的代码是一个“简单”的 setInterval (1500 毫秒),其中包含 async/await:

setInterval(async function () {

  var data = await foo();
        var obj = new mongooseModel({
          mk: data.mk,
          name: data.name,
          a: data.a,
          b: data.b,
          c: data.c,
          v: data.v,
          p: data.p,
          l: data.l,
          h: data.h,
          o: data.o,
          sn: data.sn,
          n: data.n,
        });
        obj.save(function(err, tick) {
          if (err) return console.log(err);
        });
      });
}, 1500);

还有人遇到过这个问题吗? 提前致谢!!

最佳答案

async/await 从 v7.6 开始受 Node.js 支持。您需要升级已安装的node.js版本或使用Promises。

关于node.js - NodeJS : Async/Await Raspberry Pi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46004077/

相关文章:

javascript - 尝试在 Node.js 中提供 png : Cannot read property 'end' of undefined

node.js - 如何从 Node.js 中的 http 模块返回响应?

swift - 我们如何等待 HTTP 请求完成?

c++ - 使用 AJAX 从 HTML 页面到在同一服务器上运行的 C++ 应用程序的两种方式通信

python - ffmpeg 不会停止编码,即使使用 -shortest 命令

linux - 通过终端命令打开树莓派终端?

javascript - 如何在 Electron 15 中导入菜单

node.js - fs-额外复制文件输出空白文件

php - 在 Windows 上从 PHP 运行 Grunt 命令

C++ 异步编程,如何不等待 future ?