🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

count-promises

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

count-promises

Count all the promises created between two execution points.

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

count-promises

This library helps you count the promises created from one point in time to another. The intent is to help you find out where promises may be coming from in order to optimize your application. Promises can be very expensive, especially when async_hooks are used, so it's good to keep them to a minimum if you can.

WARNING: This works on Node.js only.

Installation

This is a Node.js package on npm. Install it how you normally would install such a package.

Usage

Import it, call it to start counting, call the result to stop counting.

import startCounter from 'count-promises'

// At some point you want to start counting promises created...
const stop = startCounter()

// Now create a bunch of promises, maybe await them. Or not! For extra fun try
// awaiting non-promises and see how many promises that creates! :D

// At this point, we want to know how many promises have been created...
const total = stop()
console.log(total, 'promises have been created since `startCounter()`')

You can also pass an options object with the following two options:

  • locations: Instead of returning the total number of created promises, return an object whose keys are callsites and whose values are numbers of promises created at those callsites. Default false.
  • continuation: Omit from the count any promises created outside the async continuation starting at the startCounter() call. This is useful to eliminate any noise from other current HTTP requests, for example. Default false.

License

The MIT License. See LICENSE.txt

Keywords

promises

FAQs

Package last updated on 26 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts