1.0.1 • Published 4 years ago

s-ratelimiter v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

s-ratelimiter

Ratelimits function calls by delaying them

  • Allows for bursts of calls
  • Simple lightweight implementation

Example

import { create_ratelimiter } from 's-ratelimiter'

const ratelimit = create_ratelimiter({
    amount: 1,
    period: 1000 // once/1000ms
})

function somefunction (n) {
    return new Promise((res, rej) => {
        setTimeout(() => {
            res(`fn ${n} done`)
        }, Math.random() * 100)
    })
}

for (let n = 0; n < 10; n++)
    ratelimit(() => {
        somefunction('A' + n)
        .then(console.log)
    })