šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

@gradientedge/single-promise

Package Overview
Dependencies
Maintainers
5
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gradientedge/single-promise

Ensures that only a single promise/request is made while waiting for the original request to complete

1.0.2
latest
Source
npm
Version published
Weekly downloads
0
Maintainers
5
Weekly downloads
Ā 
Created
Source

@gradientedge/single-promise

Given a function (that returns a promise) and a key, this function ensures that the function is not called multiple times, but instead allows multiple calls to it to all wait on the same promise.

Minimal example:

import { singlePromise } from '@gradientedge/single-promise'

const grant = await singlePromise('accessToken', () => {
  return client.post('https://some-auth-endpoint')
})

In the example above, it's the anonymous function that only gets called once while there may have been multiple calls to the actual singlePromise function. The accessToken string is the key that the singlePromise function uses internally to check for an existing promise.

FAQs

Package last updated on 07 Feb 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