leaky-bucket-queue
Version:
An implementation of burstable throtling algorithm on top of rxjs
42 lines (30 loc) • 951 B
Markdown
An implementation of leaky bucket on top of `rxjs`.
Simple rate limiting are usually good enough for most scenario but they might incur unnecessary stuttering when there is attempt to make multiple call to a server API.
Leaky bucket provides a burstable solution, providing rate limit while allowing bursty traffic,
making application more responsive.
```
npm i leaky-bucket-queue
```
```ts
import { LeakyBucketQueue } from 'leaky-bucket-queue';
const queue = new LeakyBucketQueue<string>({ burstSize: 5, period: 100 });
queue.consume().subscribe({
next: console.log,
});
queue.enqueue('compter');
...
```
```js
import { LeakyBucketQueue } from 'leaky-bucket-queue';
const queue = new LeakyBucketQueue({ burstSize: 5, period: 100 });
queue.consume().subscribe({
next: console.log,
});
queue.enqueue('explode');
...
```