我在lib/helper.js
中写下了这段代码:
var myfunction = async function(x,y) {
....
return [variableA, variableB]
}
exports.myfunction = myfunction;
然后我尝试在另一个文件中使用它:
var helper = require('./helper.js');
var start = function(a,b){
....
const result = await helper.myfunction('test','test');
}
exports.start = start;
我遇到了一个错误:
await is only valid in async function
问题是什么?
await
只能在async
函数内部使用。也就是说,await
使函数变成异步函数,因此必须声明为异步函数。 - Pointy