Soy nuevo en JavaScript. Estoy tratando de hacer un retorno anticipado por error de un bloque de suscripción.
Esto es lo que tengo
public doSomething() { this.updateData(data) .subscribe((result) => { // do something }, (err) => { console.error("Error"); return; // require an early return from the block // so rest of the function isn't executed. }); // do other work }Cualquier sugerencia será apreciada.
La mejor solución sería:
public doSomething() { this.updateData(data) .subscribe((result) => { // do something // do other work }, (err) => { console.error("Error"); return; // require an early return from the block // so rest of the function isn't executed. }); }Pero también puedes usar await con async:
public async doSomething() { const result = await this.updateData(data); if (!result) return; // do other things }