我有以下代码在对抗babel时运行。现在我正在使用和声,我收到以下错误:
let adResult = await ad.isUserValid(domainPath, password);
^^
SyntaxError: Unexpected identifier
以下课程功能:
class ActiveDirectoryHelper {
constructor(options) {
this.config = options.config
this.ad = null;
}
connect() {
var config = {
url: this.config.url,
baseDN: this.config.baseDN,
attributes: this.config.attributes
};
if (this.config.account.user.length > 0) {
config.username = this.config.account.user;
config.password = this.config.account.password;
}
this.ad = new ActiveDirectory(config);
}
async isUserValid(user, password) {
return new Promise((resolve, reject) => {
this.ad.authenticate(user, password, (err, auth) => {
if (err) {
reject({
code: 500,
message: "Unknown authentication error",
entry: {}
});
}
if (auth) {
resolve({
code: 200,
message: "OK",
entry: {
user: user,
password: password
}
});
} else {
reject({
code: 400,
message: "Authentication failed",
entry: {}
});
}
});
});
}
...
exports.ActiveDirectoryHelper = ActiveDirectoryHelper;
我按如下方式使用该课程:
const ad = new ActiveDirectoryHelper({
config: adConfig
});
ad.connect();
const domainPath = domain.length > 0 ? `${domain}\\${user}` : user;
const adResult = await ad.isUserValid(domainPath, password);
我使用以下参数运行代码:
node --harmony --use_strict --harmony-async-await user.js <my parameters>
如果我在调用方法时采取等待:
const adResult = ad.isUserValid(domainPath, password);
然后我没有错误,但它也不会等到方法完成。 我已经google了错误,看起来你只能在async所在的函数中使用await。但是如果没有等待方法调用之外,它就不会等到它完成了。有什么想法吗?
答案 0 :(得分:5)