event-loop-spinner - Tiny helper to prevent blocking Node.js event loop
发布于 1 个月前 作者 9527 89 次浏览 来自 前端开源库

event-loop-spinner

Tiny helper to prevent blocking Node.js event loop.

Example

import { eventLoopSpinner } from 'event-loop-spinner';
async function cpuIntensiveOperationHandler(hugeArray) {
  for (const item of hugeArray) {
    // ...
    if (eventLoopSpinner.isStarving()) {
      await eventLoopSpinner.spin();
    }
  }
}

Reading

Node.js: How even quick async functions can block the Event-Loop, starve I/O

回到顶部