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

227
Views
Hacer función p-reintentar con promesas

Hola, quiero escribir mi propia función de reintento prometida, específicamente la función de reintento p que devuelve la promesa (no la devolución de llamada).

Y quiero hacer una función genérica que prometa, por ejemplo, la función readFile como un argumento que toma la función de reintento.

Lo estoy escribiendo en mecanografiado para un código más legible. Sin embargo, me enfrento a un problema porque cuando paso la función readFile arroja un error, this type of argument is not assignable to ...

¿Puedes darme una pista, por favor, qué estoy haciendo mal? Soy un poco principiante con mecanografiado, así que sé que probablemente no esté escrito exactamente como debería ser...

 const promisifyRetryFun = <T>(fn: ( input: () => Promise<T> | T , options?: { retries?: number } ) => Promise<T>) => async (path: string, maxRetries: number) => { let attemptCount = 0 const result = <T>(): Promise<T> => new Promise((resolve, reject) => { (fun: (path: string, callback: (error: Error, result: any) => void) => void) => { fun(path, async (error, result) => { if(attemptCount >= maxRetries) reject(error) if(error) fn(await result(), {retries: maxRetries}) attemptCount++ resolve(result) }) } }) fn(await result(), {retries: maxRetries}) } void (async () => { try{ const retr = promisifyRetryFun(retry(readFile)) const data = await (retr('./txt.txt', 3)) } catch (error) { console.error({ error }) } })()
about 4 years ago · Juan Pablo Isaza
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!