You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

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


Version published
Weekly downloads
13M
increased by0.35%
Maintainers
1
Created
Weekly downloads
 

Package description

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

Readme

Source

promise-inflight

One promise for multiple requests in flight to avoid async duplication

USAGE

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(…)

SEE ALSO

  • inflight - For the callback based function on which this is based.

STILL NEEDS

Tests!

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc