0.1.6 • Published 5 months ago

request-rate-clock v0.1.6

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
5 months ago

Request Rate Clock

This package provides a clock that can be used to limit the rate of requests to a server. It is useful for rate limiting requests to a server, for example to prevent a server from being overwhelmed by too many requests or using rate-limited APIs like the GitHub API, Spotify API, etc.

Installation

npm install request-rate-clock

Usage

import RateClock from "request-rate-clock";

const clock = RateClock.create(5, 1000); // Allow 5 requests per second

(async () => {
  for (let i = 0; i < 1000; i++) {
    await clock.acquire();
    console.log("Request", i + 1);
  }
})().catch(console.error);

API

RateClock.create(rate: number, interval: number): RateClock

0.1.6

5 months ago

0.1.5

8 months ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago