Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zacharyl2/p-limiter
Zero dependency, lightweight concurrent Promise limiter
https://github.com/zacharyl2/p-limiter
Last synced: about 1 month ago
JSON representation
Zero dependency, lightweight concurrent Promise limiter
- Host: GitHub
- URL: https://github.com/zacharyl2/p-limiter
- Owner: ZacharyL2
- License: mit
- Created: 2022-06-07T10:30:52.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-06-07T10:36:35.000Z (over 2 years ago)
- Last Synced: 2024-04-26T20:49:54.368Z (8 months ago)
- Language: TypeScript
- Size: 22.5 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# p-limiter
Zero dependency, lightweight concurrent Promise limiter
## Install
```bash
yarn add p-limiter
# or
pnpm add p-limiter
```## Usage
```ts
import Limiter from 'p-limiter';const limiter = new Limiter(3);
const mockPromise = (i: number) =>
new Promise((resolve) => {
console.log(
`➕ Start Task${i} -`,
`Active Count: ${limiter.activeCount}`,
`Pending Count: ${limiter.pendingCount}`
);
setTimeout(() => {
console.log(
`✅ Complete Task${i} -`,
`Active Count: ${limiter.activeCount}`,
`Pending Count: ${limiter.pendingCount}`
);
resolve(i);
}, i * 1000);
});(async () => {
const results = await Promise.allSettled(
[...new Array(6)].map((_, i) => limiter.limit(() => mockPromise(i)))
);
console.log('results: ', results);
})();
```## License
[MIT License](./LICENSE)
## Related
- [p-limit](https://github.com/sindresorhus/p-limit) - Run multiple promise-returning & async functions with limited concurrency