Bird
0
0

Which method would you use to schedule a callback to run immediately after the current operation but before any I/O events?

easy📝 Conceptual Q2 of 15
Node.js - Timers and Scheduling
Which method would you use to schedule a callback to run immediately after the current operation but before any I/O events?
AsetTimeout with 0 delay
BsetImmediate
Cprocess.nextTick
DPromise.resolve().then()
Step-by-Step Solution
Solution:
  1. Step 1: Identify callback timing

    process.nextTick schedules callbacks to run immediately after the current operation, before the event loop continues.
  2. Step 2: Compare with other methods

    setImmediate runs after I/O events, setTimeout with 0 delay runs in timers phase, and Promise.resolve().then() runs microtasks but after nextTick.
  3. Final Answer:

    process.nextTick -> Option C
  4. Quick Check:

    Immediate next operation = B [OK]
Quick Trick: Use nextTick for immediate post-operation callbacks [OK]
Common Mistakes:
  • Using setImmediate for immediate callbacks
  • Confusing microtasks with nextTick
  • Assuming setTimeout(0) runs immediately

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes