1.0.4 โ€ข Published 6 months ago

@bytekit/throttle v1.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

@bytekit/throttle

A simple, type-safe, and efficient throttling utility for managing execution rate limits in JavaScript/TypeScript.

Features

  • โœ… Supports both void and promise-returning tasks
  • โณ Enforces throttling using token-bucket-style logic
  • ๐Ÿ”ฅ Simple, performant, and dependency-free
  • ๐Ÿงช 100% test and mutation coverage
  • ๐Ÿ’ฅ Throws when queue is full

Installation

npm install @bytekit/throttle

or

yarn add @bytekit/throttle

Usage

ThrottledQueue

import {ThrottledQueue} from "@bytekit/throttle";

const queue = new ThrottledQueue(5, 1000); // 5 tasks per 1000ms

queue.enqueue(() => {
  console.log("Task executed");
});

ThrottledPromiseQueue

import {ThrottledPromiseQueue} from "@bytekit/throttle";

const queue = new ThrottledPromiseQueue(2, 1000);

const result = await queue.submit(async () => {
  await new Promise((resolve) => setTimeout(resolve, 100));
  return "Hello, throttling!";
});

console.log(result); // "Hello, throttling!"

License

ISC

1.0.4

6 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago