# busy

> Detect if event loop is busy.

Latest version **0.1.1** (published 2013-05-12) · 0 weekly downloads

## Install

```sh
npm install busy
pnpm add busy
yarn add busy
bun add busy
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2013-05-12 |
| First published | 2013-05-12 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Oleg Slobodskoi |
| Maintainers | kof |
| Keywords | event, loop, busy, blocked, warn |

## Links

- npm: https://www.npmjs.com/package/busy
- Repository: git@github.com:kof/node-busy
- npm.io page: https://npm.io/package/busy

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 0.1.1 (latest) — 2013-05-12
- 0.1.0 — 2013-05-12

## README

## Detect if event loop is busy.

The idea is not new, implementation probably too. I just saw this https://github.com/lloyd/node-toobusy and found it useful. This projects does pretty the same but in pure javascript.

## Things you can do

- Log how busy is the loop
- Stop accepting new tasks
- Warn yourself
- Scale up the app

## Example (shameless copied from toobusy)

    var busy = require('busy'),
        express = require('express');

    var app = express();

    var busyCheck = busy(function(amount) {
        console.log('Loop was busy for', amount, 'ms');
    });

    // middleware which blocks requests when we're too busy
    app.use(function(req, res, next) {
        if (busyCheck.blocked) {
            res.send(503, "I'm busy right now, sorry.");
        } else {
            next();
        }
    });

    app.get('/', function(req, res) {
        // processing the request requires some work!
        var i = 0;
        while (i < 1e5) i++;
        res.send("I counted to " + i);
    });

    var server = app.listen(3000);

    process.on('SIGINT', function() {
        server.close();
        // calling .stop allows your process to exit normally
        busyCheck.stop();
        process.exit();
    });

## Api `busy([options], [callback])`

Optional options:

    - `max` max time in ms alowed to be busy, default is 100ms
    - `interval` how often to check the state in ms, default is 50ms

Optional callback is called every time the event loop was busy for longer amount of time than defined in `max`. Passed value is amount of ms the loop was blocked for.


    var busyCheck = busy();

    busyCheck.blocked; // Is true if by the last check, max was exceeded
    busyCheck.blockedFor; // Number in ms the loop was blocked for, during the last check

    busyCheck.stop(); // Stop doing checks

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