async-debug
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Asynchronous Operations Debugger


npm version npm downloads

About

async-debug is a Node.js module that debugs your asynchronous operations, inspired by asyncio debug mode of python.

Currently, the only feature of this module is to listen for your asynchronous operations and log them to the console if they take too long to complete (considered "slow").

Limitation

As async_hooks does not provide information about the execution context, this module cannot provide the detailed location of where the operation was started like Python's asyncio. I will try to find a way to do this in the future. If you have any ideas, please let me know.

Installation

npm install async-debug
yarn add async-debug
pnpm add async-debug

Usage

import { configure } from "async-debug";

const asyncDebugger = configure({
    longTaskThreshold: 250, // 0.25 seconds, default is 300 (0.3 seconds)
})

if (process.env.NODE_ENV === 'development') {
    asyncDebugger.enable();
}

// Your code here

// Output:
// Executing asynchronous operation 15 using HTTPCLIENTREQUEST took 313.654224999249ms to complete.

And that's it! You can now debug your asynchronous operations.

If you want to setup different thresholds for different operations, you can pass object to the longTaskThreshold parameter like below.

configure({
    longTaskThreshold: {
        HTTPCLIENTREQUEST: 300,
        TCPCONNECTWRAP: 100,
        FSREQCALLBACK: 150,
        // See https://nodejs.org/api/async_hooks.html#type
    }
})

Configuration

All options are described as JSDoc comments, but if I think it's necessary, I'll add them here later.

Package Sidebar

Install

npm i async-debug

Weekly Downloads

1

Version

1.0.1

License

Apache-2.0

Unpacked Size

20.4 kB

Total Files

6

Last publish

Collaborators

  • zero734kr