Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mytecor/sweet-limiter
Promise-based limiter
https://github.com/mytecor/sweet-limiter
Last synced: 4 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 (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-09-23T23:52:58.000Z (about 3 years ago)
- Last Synced: 2024-04-23T09:42:28.510Z (8 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 rpsasync 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))
}
```