Bird
0
0

How can you ensure that a callback runs after all process.nextTick callbacks but before any timers or I/O callbacks?

hard📝 Application Q9 of 15
Node.js - Timers and Scheduling
How can you ensure that a callback runs after all process.nextTick callbacks but before any timers or I/O callbacks?
AUse setImmediate
BChain a Promise.then() after nextTick
CUse setTimeout with 0 delay
DUse process.nextTick again
Step-by-Step Solution
Solution:
  1. Step 1: Understand callback phases

    process.nextTick callbacks run before microtasks like Promises.
  2. Step 2: Use Promise.then() to run after nextTick

    Promises run in microtask queue after nextTick callbacks but before timers and I/O.
  3. Final Answer:

    Chain a Promise.then() after nextTick -> Option B
  4. Quick Check:

    Promise microtasks run after nextTick = C [OK]
Quick Trick: Use Promise.then() to run after nextTick but before timers [OK]
Common Mistakes:
  • Assuming setImmediate runs before timers
  • Using nextTick again causing immediate run
  • Confusing timers and microtasks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes