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

166
Views
¿Hay una mejor manera de escribir una función con dos async?

tengo esta funcion:

 private async get(iD: string): Promise<Function> { return async () => { const tallConfig = await longCrudService.getHalf(iD); const stream: Stream = tallConfig.stream; const response = this.createUrl(tallConfig, stream); return response; }; }

¿Hay alguna forma en que pueda volver a escribir esto pero sin usar doble asíncrono, como si hubiera alguna manera en que pudiera volver a escribir esto usando solo el asíncrono de la función y eliminando el asíncrono interno?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

El único uso decente de async es cuando necesita await directamente dentro. Como no lo está haciendo para la función externa, puede eliminarla; solo la función interna está haciendo uso de await .

 private get(iD: string): Promise <Function> => async () => { const tallConfig = await longCrudService.getHalf(iD); const stream: Stream = tallConfig.stream; const response = this.createUrl(tallConfig, stream); return response; }

También puede eliminar los async por completo si lo desea, a cambio de .then .

 private get(iD: string): Promise <Function> => () => longCrudService.getHalf(iD) .then(tallConfig => this.createUrl(tallConfig, tallConfig.stream));
about 4 years ago · Juan Pablo Isaza Report

0

No hay necesidad de una función interna que pueda reescribir como tal:

 private async get(iD: string): Promise<Function> { const tallConfig = await longCrudService.getHalf(iD); const stream: Stream = tallConfig.stream; return this.createUrl(tallConfig, stream); }

Asegúrese de que la persona que llama no necesite otra llamada de función, ya que esto devolvería una promesa como se especifica en la firma de su función.

about 4 years ago · Juan Pablo Isaza 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!