Я пытаюсь преобразовать эту функцию в async / await:
finddevice(s: any) {
if (s !== '') {
for (let i = 1; i < 255; i++) {
this.ws.ping(s + '.' + i).subscribe(res => {
console.log('res', res)
if (res) {
try { throw i }
catch (ii) {
let myipfind = s + '.' + ii;
this.myipdevice = myipfind;
}
}
},(error) => {
console.log('got error from finddevice', error);
})
}
}
}
Я следую Async / await и пытаюсь изменить свою функцию.Однако ничего не происходит, неправильные ответы не прекращаются.
promiseFun(){
this.s = `${this.myip & 0xFF}.${(this.myip >> 8) & 0xFF}.${(this.myip >> 16) & 0xFF}`
return new Promise((resolve,reject)=>{
if (s !== '') {
for (let i = 1; i < 255; i++) {
this.ws.ping(s + '.' + i).subscribe(res => {
if (res) {
try { throw i }
catch (ii) {
let myipfind = s + '.' + ii;
this.myipdevice = myipfind;
}
}
},(error) => {
console.log('got error from finddevice', error);
})
}
}
}
setTimeout(()=>{
resolve("Resolved");
},2000);
})
}
async makeCall() {
try {
let successData= await this.promiseFun();
console.log(successData);
} catch (error) {
console.log(error);
}
}
Правильный ответ достигнут, но неправильные ответы по-прежнему не прекращаются.
Любая идея, как остановить неправильный ответ