🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

promise-inflight

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

promise-inflight

One promise for multiple requests in flight to avoid async duplication

1.0.1
latest
Source
npm
Version published
Weekly downloads
12M
-12.26%
Maintainers
1
Weekly downloads
 
Created

What is promise-inflight?

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.

What are promise-inflight's main functionalities?

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);

Other packages similar to promise-inflight

FAQs

Package last updated on 26 Feb 2017

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