【发布时间】:2018-03-01 07:26:11
【问题描述】:
当我在 nodejs 中使用 async 或 await 时,我得到了意外的标识符。我在节点版本 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步 第三步 第二步
【问题讨论】:
-
是的,有一种方法:向我们展示您的代码。
-
用代码更新了问题。谢谢
标签: javascript promise async-await