0.0.8 • Published 3 years ago

big-leak v0.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

big-leak 🌊

Build Status

Leaky bucket implementation

Table of contents

Installation

NPM

npm install big-leak --save

Yarn

yarn add big-leak

Usage

const limiter = require("big-leak")({
	url: "memory://", // Dataman connection url
	prefix: "leaky:", // Redis key prefix
	delimiter: ":", // Redix key delimiter
	initialValue: 0, // How full do you want bucket to be?
	maxValue: 20, // How much do you want bucket to be able to fill up?
	refillTime: 24 * 60 * 60 * 1000, // 1-day - how often should bucket be filled up
	refillAmount: 20, // How much should bucket be refilled each refill time
	updateType: "float" // Do you want to refill bucket less thatn refillAmount?
});

const limit = limiter.limit("send-request", 123);

const sendRequest = limit.wrapper((url) => {
	console.log("Sending request");

	return Promise.resolve();
});

Array(50).fill(true).reduce((prev) => prev.then(sendRequest), Promise.resolve());

Authors

0.0.8

3 years ago

0.0.5

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago