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

179
Views
Siga verificando la conexión si está disponible en Node y borre setTimeout

En el nodo, sigo verificando si la conexión está disponible, si lo está, obtendrá un token y lo almacenará en la variable, pero si no, se generará un error de captura y luego se ejecutará setTimeout para intentarlo nuevamente en 2 segundos.

Pero creo que necesito una forma limpia de borrar setTimeout porque cuando lo registro, sigo obteniendo un número más alto en Symbol(asyncId) ¿Me parece que sigue agregando setTimeout cada vez más a la memoria?

 export const getToken = async () => { try { if (!GLOBAL_VARS.authToken) { await auth(`Getting token`) } // Do more stuff } catch (error: any) { tokenTimeout() } } getToken()
 export const tokenTimeout = () => { setTimeout(() => { getToken() }, 2000) }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Sí, agregará más setTimeouts a la memoria.

puedes borrarlo así:

 export const tokenTimeout = setTimeout(() => { getToken() }, 2000) export const getToken = async () => { try { if (!GLOBAL_VARS.authToken) { await auth(`Getting token`) } // Do more stuff } catch (error: any) { const timeout = tokenTimeout() } } getToken() /// use it wherever you want clearTimeout(timeout);
about 4 years ago · Juan Pablo Isaza Report

0

La memoria aumentará debido a lo que sea que esté haciendo con auth() y no porque esté creando tiempos de espera.

El problema que veo con su código no es realmente usar async await correctamente. Debería parecerse más

 const sleep = (ms) => new Promise((resolve) => { setTimeout(resolve, ms); }); export const getToken = async (count = 0) => { try { if (!GLOBAL_VARS.authToken) { await auth(`Getting token`); } } catch (error: any) { await sleep(2000); if (count < 10) await getToken(++count); else throw new Error('Taking too long to get auth token'); } } (async function () { await getToken(); })();
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!