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

256
Views
Node.js: agregar la llamada process.nextTick() al código de nivel superior afecta el orden de setTimeout() y setImmediate()

Como se explica en las guías oficiales ( https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/#setimmediate-vs-settimeout ), si ejecuto el siguiente fragmento, obtengo un orden diferente para registros, a veces immediate primero y a veces tiempo de timeout primero, es decir, el orden no es determinista :

 setImmediate(() => { console.log("immediate"); }); setTimeout(() => { console.log("timeout"); }, 0);

Producción:

 > node index.js immediate timeout > node index.js immediate timeout > node index.js timeout immediate

Sin embargo, si agrego la llamada a process.nextTick() a la mezcla, inesperadamente, se corrige el orden de tiempo de timeout e immediate (el tiempo de timeout siempre se imprime antes de immediate ):

 setImmediate(() => { console.log("immediate"); }); setTimeout(() => { console.log("timeout"); }, 0); process.nextTick(() => { console.log("next tick"); });

Producción:

 > node index.js next tick timeout immediate > node index.js next tick timeout immediate > node index.js next tick timeout immediate

No pude entender cómo process.nextTick() afecta el orden de tiempo de timeout e immediate . ¿Puede alguien ayudarme a entender lo que está sucediendo internamente aquí?

over 4 years ago · Santiago Trujillo
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!