
Research
Malicious fezbox npm Package Steals Browser Passwords from Cookies via Innovative QR Code Steganographic Technique
A malicious package uses a QR code as steganography in an innovative technique.
promise-inflight
Advanced tools
One promise for multiple requests in flight to avoid async duplication
The promise-inflight npm package is designed to ensure that a promise with a specific key is only in flight once. If multiple requests are made with the same key, they will all receive the same promise, preventing duplicate operations. This is particularly useful for avoiding redundant network requests or expensive computations when the same operation might be triggered multiple times concurrently.
Single instance promise management
This feature ensures that for a given key, only one promise is in flight. If the same key is used in subsequent calls while the promise is still pending, the same promise is returned. This avoids executing the fetch function multiple times for the same data.
const inflight = require('promise-inflight');
async function fetchData(key, fetchFunction) {
return inflight(key, () => fetchFunction());
}
// Usage example
fetchData('user-data', () => fetch('https://api.example.com/user')).then(console.log);
p-memoize is a package that memoizes the result of a promise-returning or async function. It can cache results based on the input arguments and offers more extensive configuration options for cache management compared to promise-inflight, which focuses solely on managing concurrent identical requests.
Similar to p-memoize, async-memoize provides memoization for asynchronous functions. It supports multiple strategies for cache eviction and can handle concurrent execution more flexibly than promise-inflight, which is specifically tailored for handling cases where identical promises should not be executed multiple times concurrently.
One promise for multiple requests in flight to avoid async duplication
const inflight = require('promise-inflight')
// some request that does some stuff
function req(key) {
// key is any random string. like a url or filename or whatever.
return inflight(key, () => {
// this is where you'd fetch the url or whatever
return Promise.delay(100)
})
}
// only assigns a single setTimeout
// when it dings, all thens get called with the same result. (There's only
// one underlying promise.)
req('foo').then(…)
req('foo').then(…)
req('foo').then(…)
req('foo').then(…)
Tests!
FAQs
One promise for multiple requests in flight to avoid async duplication
The npm package promise-inflight receives a total of 12,815,247 weekly downloads. As such, promise-inflight popularity was classified as popular.
We found that promise-inflight demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.
Application Security
/Research
/Security News
Socket detected multiple compromised CrowdStrike npm packages, continuing the "Shai-Hulud" supply chain attack that has now impacted nearly 500 packages.