Bird
0
0

You want to execute a heavy CPU task but ensure that I/O callbacks are not blocked. Which scheduling method should you use to defer the task without blocking I/O?

hard📝 Application Q8 of 15
Node.js - Timers and Scheduling
You want to execute a heavy CPU task but ensure that I/O callbacks are not blocked. Which scheduling method should you use to defer the task without blocking I/O?
AsetImmediate
BSynchronous loop
CsetTimeout with 0 delay
Dprocess.nextTick
Step-by-Step Solution
Solution:
  1. Step 1: Understand blocking behavior

    process.nextTick runs before I/O events and can block them if used for heavy tasks.
  2. Step 2: Choose method that defers after I/O

    setImmediate schedules callbacks after I/O events, allowing I/O to proceed before heavy task runs.
  3. Final Answer:

    setImmediate -> Option A
  4. Quick Check:

    Defer heavy task after I/O = D [OK]
Quick Trick: Use setImmediate to avoid blocking I/O with heavy tasks [OK]
Common Mistakes:
  • Using nextTick and blocking I/O
  • Assuming setTimeout(0) is better for deferring
  • Running heavy tasks synchronously

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes