New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

promise-dedup

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-dedup

Deduplicate any promise

latest
Source
npmnpm
Version
1.3.0
Version published
Weekly downloads
456
-37.45%
Maintainers
1
Weekly downloads
 
Created
Source

promise-dedup

Deduplicate any promise.

Cache promises by key

By default, dedup caches promises until they are settled:

import { dedup } from "promise-dedup";

async function doStuff() {
  await new Promise((resolve) => setTimeout(resolve, 5000)); // Waiting five seconds
  return 5;
}

dedup(doStuff, ["key", 42]);
dedup(doStuff, ["key", 42]);
dedup(doStuff, ["key", 42]);

// doStuff is only called once at this point

await new Promise((resolve) => setTimeout(resolve, 6000)); // Waiting six seconds

dedup(doStuff, ["key", 42]); // doStuff is called again because the previous promise settled

The third optional argument of dedup is the stale policy. By default, it's "settled". It can be set to "never" or to a number. When set to "never", the promise never gets stale. When set to a number, the promise gets stale after a timeout of that number as milliseconds.

Keywords

promise

FAQs

Package last updated on 13 Jun 2022

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