got-plugin-debounce

1.0.3 • Public • Published

Got Plugin Debounce

Ensure a time delay between HTTP requests.
Use when targeting endpoints with rate limits.

Install

npm install got-plugin-debounce

Usage

import got from 'got';
import plugin from 'got-plugin-debounce';

const client = got
  .extend(plugin) // load plugin
  .extend({ debounce: [350, 450] }) // random value from 350ms to 450ms between 2 requests
  // .extend({ debounce: 350 }) // fixed 350 ms between 2 requests
  
  const startedAt = Date.now();
  await Promise.all([
      client('https://www.google.com'),
      client('https://www.google.com'),
      client('https://www.google.com'),
      client('https://www.google.com'),
    ]);
  const elapsed = Date.now() - startedAt;
  
  console.log(elapsed > 1000); // true

Readme

Keywords

none

Package Sidebar

Install

npm i got-plugin-debounce

Weekly Downloads

3

Version

1.0.3

License

MIT

Unpacked Size

2.49 kB

Total Files

4

Last publish

Collaborators

  • jeanbmar