Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.1K
Views
async await en la declaración de cambio de caso no funciona

¿Podemos esperar la resolución de una promesa dentro de la declaración de cambio de caso, usando la palabra clave await? en mi componente angular tengo el siguiente código que bloquea mi aplicación.

 switch (this.status) { case 'opened': break; case 'payed': this.getIntervalStatusSubscription.unsubscribe(); this.localStorageService.storePaymentIsMade(true); await this.dbService.addOrderPaymentResult(ProcessResult.done, this.printerVMService.getSessionId()).toPromise(); this.router.navigate(['welcome/paying/paying_accepted']); break; case 'closed': this.getIntervalStatusSubscription.unsubscribe(); this.paymentSessionIsClosed = true; await this.dbService.addOrderPaymentResult(ProcessResult.error, this.printerVMService.getSessionId()).toPromise(); this.router.navigate(['welcome']); break; case 'used': this.getIntervalStatusSubscription.unsubscribe(); this.router.navigate(['welcome']); break; default: console.error('status don\'t exist'); this.utils.displayAlertError(this.device.getIntervalStatus); this.router.navigate(['welcome']); }

Después de varias pruebas, me parece que el error proviene de líneas que comienzan con await . ¿Me puede decir lo que está mal por favor. Me gustaría this.dbService.addOrderPaymentResult(ProcessResult.done, this.printerVMService.getSessionId()) que devuelve un observable que se ejecuta sincrónicamente antes de ir a this.router.navigate(['welcome/paying/paying_accepted']); es por eso que elegí usar toPromise() y await

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Sí tu puedes:

 async function trySwitch(status) { switch(status) { case 'opened': console.log('1'); break; case 'closed': console.log('2'); await new Promise(r => setTimeout(r, 1000)); console.log('3'); break; } } trySwitch('opened'); trySwitch('closed');

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!