NodeJS:异步/等待 Raspberry Pi
NodeJS: Async / Await Raspberry Pi
我有一些代码可以在我的日常计算机上完美运行,但在尝试从 raspberry pi(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
我的代码是 'simple' setInterval(1500 毫秒),其中包含异步/等待:
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。
我有一些代码可以在我的日常计算机上完美运行,但在尝试从 raspberry pi(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
我的代码是 'simple' setInterval(1500 毫秒),其中包含异步/等待:
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。