Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mcollina/fastp
Promise utilities
https://github.com/mcollina/fastp
Last synced: about 2 months ago
JSON representation
Promise utilities
- Host: GitHub
- URL: https://github.com/mcollina/fastp
- Owner: mcollina
- License: mit
- Created: 2024-02-03T23:46:10.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-10-21T15:30:20.000Z (2 months ago)
- Last Synced: 2024-10-24T23:07:52.912Z (about 2 months ago)
- Language: JavaScript
- Size: 27.3 KB
- Stars: 20
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fastp
Fast promise utilities
## Install
```js
npm i fastp
```## API
### `p.limit(concurrency=1)`
Limit the number of promises resolved concurrently.
Offers the same API of [p-limit](http://npm.im/p-limit)```js
import p from 'fastp'
import { settimeout as sleep } from 'node:timers/promises'
const limit = p.limit(2);const result1 = await Promise.all([
limit(() => sleep(300, 'foo')),
limit(() => sleep(200, 'bar')),
limit(() => sleep(100, 'baz'))
]);
console.log(result1)
// [ 'foo', 'bar', 'baz' ]const result2 = await Promise.race([
limit(() => sleep(300, 'foo')),
limit(() => sleep(200, 'bar')),
limit(() => sleep(100, 'baz'))
]);
console.log(result2)
// 'bar'
```It's over 3x faster than `p-limit`
```
╔══════════════╤═════════╤═════════════════╤═══════════╗
║ Slower tests │ Samples │ Result │ Tolerance ║
╟──────────────┼─────────┼─────────────────┼───────────╢
║ pLimit │ 10000 │ 24994.77 op/sec │ ± 3.08 % ║
╟──────────────┼─────────┼─────────────────┼───────────╢
║ Fastest test │ Samples │ Result │ Tolerance ║
╟──────────────┼─────────┼─────────────────┼───────────╢
║ fastp.limit │ 10000 │ 91958.28 op/sec │ ± 5.76 % ║
╚══════════════╧═════════╧═════════════════╧═══════════╝
```## License
MIT