当我在Node.js中使用async或await时,出现了意外的标识符错误。我使用的是Node版本8.5.0。这完全阻碍了我的进展。有没有什么方法可以解决这个问题?
async function methodA(options) {
rp(options)
.then(function (body) {
serviceClusterData = JSON.parse(body);
console.log("Step 2");
console.log("Getting cluster details from zookeeper");
})
.catch(function (err) {
console.log("Get failed!");
});
}
await methodA(options);
console.log("Step 3!");
尝试了第一个答案后,我做了如下操作:
var serviceClusterData = "";
console.log("Step 1!");
////////////////////
async function methodA(options) {
await rp(options)
.then(function (body) {
serviceClusterData = JSON.parse(body);
console.log("Step 2");
console.log("Getting cluster details from zookeeper");
})
.catch(function (err) {
console.log("Get failed!");
});
}
methodA(options);
console.log("whoops Step 3!");
仍然出现顺序问题 :( 步骤1 步骤3 步骤2