You are building a high-performance API in Node.js, and you need to implement long-running computations without blocking incoming requests. How would you leverage the Event Loop and Non-Blocking I/O to achieve this?

  • Use setTimeout for long-running computations.
  • Offload computations to a separate thread using worker_threads.
  • Block the Event Loop until computations are complete.
  • Use synchronous I/O for improved performance.
To implement long-running computations without blocking incoming requests in Node.js, you should use worker_threads to offload the CPU-intensive tasks to separate threads, allowing the Event Loop to remain responsive. Options a, c, and d are not recommended because they involve blocking or potentially blocking the Event Loop, which can lead to poor performance and unresponsiveness.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *