Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

blocked

visionmedia357.1kMIT1.3.0TypeScript support: definitely-typed

check if the event loop is blocked

block, event, loop, performance

readme

blocked

Check if a node event loop is blocked.

If You're running Node.js 8+ you can get a stacktrace pointing to the blocking function using very similar blocked-at package.

Installation

$ npm install blocked

Description

The blocked() function reports every value over the configured threshold (defaulted to 10ms). You can then do whatever you want with that value, graph it, log it, alert, etc.

The process won't be kept open through this.

Params and return value

var timer = blocked(fn, options);
  • fn: The callback function to execute when the event loop is blocked. Will send in the amount of time in ms that the event loop was blocked.
  • options: Optional. Options object to configure the behaviour.
    • threshold determines the amount of ms used to determine if the function callback should be executed; useful to speed up tests.
    • interval determines the frequency with which the event loop is checked in ms.
blocked(function(ms) {
    console.log("Blocked");
}, {threshold:1, interval: 1000});

Returns: A reference to the timer. Useful for clearing the timer.

var timer = blocked(function(ms) {
                console.log("Blocked");
            });
clearInterval(timer);

License

MIT

changelog

1.3.0 / 2019-10-25

  • Add interval to options

1.2.0 / 2016-02-12

  • Return a reference to the timer
  • Add options to the constructor to be able to parameterize the threshold
  • Tests and coverage
  • Removed make file and replaced with NPM scripts

1.1.0 / 2015-01-12

  • unref interval

1.0.0 / 2014-06-10

  • round ms