# event-loop-spinner

> Tiny helper to prevent blocking Node.js event loop

Latest version **2.3.3** (published 2026-07-02) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install event-loop-spinner
pnpm add event-loop-spinner
yarn add event-loop-spinner
bun add event-loop-spinner
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 2.3.3 |
| Published | 2026-07-02 |
| First published | 2019-11-08 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=18 |
| Dependencies | 1 |
| Unpacked size | 5.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 22 |
| Author | snyk.io |
| Maintainers | snyk-admin |

## Links

- npm: https://www.npmjs.com/package/event-loop-spinner
- Repository: https://github.com/snyk/event-loop-spinner
- Homepage: https://github.com/snyk/event-loop-spinner#readme
- Issues: https://github.com/snyk/event-loop-spinner/issues
- npm.io page: https://npm.io/package/event-loop-spinner

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.6.3

## Recent versions

- 2.3.3 (latest) — 2026-07-02
- 2.3.2 — 2024-06-19
- 2.2.0 — 2022-01-18
- 2.1.0 — 2021-03-01
- 2.0.0 — 2020-06-03
- 1.1.0 — 2020-01-21
- 1.0.1 — 2019-11-08

## README

# event-loop-spinner

Tiny helper to prevent blocking Node.js event loop.

## Example

```typescript
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](https://snyk.io/blog/nodejs-how-even-quick-async-functions-can-block-the-event-loop-starve-io/)


## How does this help?

Node can only run one bit of JS at a time. While it is running this bit of JS, it does nothing else.
It doesn't fire timers. It doesn't accept TCP connections from clients.

In fact, Node doesn't even do these things when it finishes running one bit of JS. It prefers to
immediately run the next bit of JS. It does this for "a while".

This gives you two amazingly powerful ways to shoot yourself in the foot; it's great! Just like C++.

That is, if some node process either:
 * contains some JS code which runs for "too long", or
 * handles too many concurrent work items, resulting in lots of JS to run,

..then it won't handle network requests, or let anyone else do any JS. This can result in the
application appearing unresponsive for seconds or minutes. (Yes, we really see minutes.)

`event-loop-spinner` masks this problem. The `spin()` method allows Node to stop running this JS
function, and its friends, and do some other JS, or do some IO. This significantly shortens the
time before more networking is done (i.e. a response is sent to a client), and/or other people's
JS is run, improving responsiveness.

---
_Source: https://npm.io/package/event-loop-spinner · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
