0.0.8 • Published 3 years ago
big-leak v0.0.8
big-leak 🌊
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());