https://github.com/mytecor/sweet-limiter
Promise-based limiter
https://github.com/mytecor/sweet-limiter
Last synced: 29 days ago
JSON representation
Promise-based limiter
- Host: GitHub
- URL: https://github.com/mytecor/sweet-limiter
- Owner: mytecor
- License: mit
- Created: 2020-12-06T22:54:16.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-09-23T23:52:58.000Z (about 4 years ago)
- Last Synced: 2025-09-16T13:04:38.248Z (about 2 months ago)
- Language: TypeScript
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# sweet-limiter
Promise-based limiter
### Usage example
```js
import Limiter from 'sweet-limiter'
let limiter = new Limiter(30) // 30 rps
async function chat1() {
for(let i = 1; i <= 100; i++) {
await limiter.next()
await fakeRPC(100, `chat 1: ${i}`)
}
}
async function chat2() {
for(let i = 1; i <= 100; i++) {
await limiter.next(10) // in example sendMediaGroup with 10 media
await fakeRPC(1000, `chat 2: ${i}`)
}
}
chat1()
chat2()
function fakeRPC(timeout, message) {
console.log(message)
return new Promise(resolve => setTimeout(resolve, timeout))
}
```