Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
promise-make-counter
Advanced tools
A simple function that makes a counter-based promise, which can be incremented and decremented, and it resolves once its counter reaches zero.
A simple function that makes a counter-based promise, which can be incremented and decremented, and it resolves once its counter reaches zero.
This is an alternative to creating a promise that waits on many other promises to resolve. You can do that, but creating many promises can be surprisingly slow, instead you could use this package, switch internally to using callbacks-style APIs rather than async/await-style APIs, and just increment the counter at the start of each callback, and decrement it at its end, once its job is done.
npm install --save promise-make-counter
import fs from 'node:fs';
import makeCounterPromise from 'promise-make-counter';
// Let's create a counter-based promise
const {promise, isPending, increment, decrement} = makeCounterPromise ();
// Now let's do some work that's tracked by our counter-based promise
// It's important to always increment at the start, and decrement at the end
for ( const filePath of filePaths ) {
increment ();
fs.readFile ( filePath, 'utf8', ( error, data ) => {
// Do something here...
decrement ();
});
}
// Let's wait for the counter-based promise to resolve
// This will happen once its internal counter will reach zero
await promise;
MIT © Fabio Spampinato
FAQs
A simple function that makes a counter-based promise, which can be incremented and decremented, and it resolves once its counter reaches zero.
The npm package promise-make-counter receives a total of 23,030 weekly downloads. As such, promise-make-counter popularity was classified as popular.
We found that promise-make-counter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.