Closed rickyk586 closed 5 years ago
I think this is tested here: https://github.com/microlinkhq/async-ratelimiter/blob/master/test/index.js#L339
perhaps it makes a difference if it reaches 0
The same is happening in the original library 🤔
'use strict'
const RateLimiter = require('ratelimiter')
//const RateLimiter = require('.')
const Redis = require('ioredis')
const { promisify } = require('util')
const limiter = new RateLimiter({
duration: 2000,
max: 2,
id: 'something',
db: new Redis()
})
const get = promisify(limiter.get.bind(limiter))
let index = -1
setInterval(async () => {
console.log('---')
console.log('iteration', ++index)
const r = await get()
console.log('value', r)
}, 100)
Can you open the issue there as well?
logs 2, 1, 0, 0, 0, 0, 0...
I would expect it to free up a slot after 2 seconds and r.remaining to = 1. If I change the setInterval to 1000, it works as expected.