Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pback

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

pback

_(piggy-back)_

  • 0.0.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

pback

(piggy-back)

Any pure function in the form (...args) => Promise, can be passed to deduper and subsequent requests with the same arguments will wait for the result of the first one that arrived. This is meant to prevent unnecessary http or database requests.

npm install
/**
 * @param keyFn function that generates key for the internal cache, receives same params as the deduped function
 * @param fn function whose invocation is being deduplicated
 * @param options { timeout } - timeout in ms after which the task fails, default is 10s
 * @returns promise (same as the fn)
 */
  import { deduper } from 'pback';

  // an expensive async task that'll be repeated
  const getUser = (userId: number) => {
    return fetch(`/api/user/${userId.toString()}`)
  };

  const dedGetUser = deduper(id => id, getUser, {
    timeout: 1000,
  });


  // Consecutive requests will make only 2 fetches (as long as they arrive)
  getUser(1);
  // later
  getUser(2);
  // ...
  getUser(2);
  // ...
  getUser(1);
  // ...
  getUser(1);


FAQs

Package last updated on 15 May 2021

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc