我具有此功能:
function authentification(jsonHeder: any): Promise<boolean> {
return new Promise(function(resolve, reject) {
const ws = new WebSocket('ws://localhost:8000');
if (!jsonHeder.email || !jsonHeder.password) reject(new Error('bad request'));
ws.onopen = async function() {
ws.send(JSON.stringify({
command: '-userLogin',
instanceIdentifier: jsonHeder.email,
password: jsonHeder.password
})
);
};
ws.onmessage = async function(message) {
const json = JSON.parse(message.data.toString());
if (json.isError === false) {
resolve();
} else {
reject(new Error('bad request'));
}
}
});
}
并且我试图获得认证的批准,当我尝试打印结果时,我会收到Promise {}。
调用函数如下:
const result = authentification(jsonHeder);
console.log('result: ', result);
,当我尝试让操作员等待时,我收到了编译错误。我该怎么办?