@gradientedge/single-promise
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

@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.

Readme

Keywords

none

Package Sidebar

Install

npm i @gradientedge/single-promise

Weekly Downloads

158

Version

1.0.2

License

ISC

Unpacked Size

6.33 kB

Total Files

10

Last publish

Collaborators

  • gradient_edge
  • spocked
  • hemalshah
  • jameswiltshire
  • jimmythomson