Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/waldemarnt/concurrent-promises
This package allows safe promise concurrency
https://github.com/waldemarnt/concurrent-promises
concurrency concurrent-programming limit promise promises promises-concurrent
Last synced: 20 days ago
JSON representation
This package allows safe promise concurrency
- Host: GitHub
- URL: https://github.com/waldemarnt/concurrent-promises
- Owner: waldemarnt
- Created: 2017-06-06T14:39:11.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-06-09T14:45:05.000Z (over 7 years ago)
- Last Synced: 2024-09-14T22:48:16.546Z (about 2 months ago)
- Topics: concurrency, concurrent-programming, limit, promise, promises, promises-concurrent
- Language: JavaScript
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Concurrent-promises
[![Build Status](https://travis-ci.org/waldemarnt/concurrent-promises.svg?branch=master)](https://travis-ci.org/waldemarnt/concurrent-promises)Sometimes we want to limit the number of concurrent promises like in HTTP requests or I/O. This library allows limit the number of concorrency.
Different from libraries like: https://github.com/timdp/es6-promise-pool it allows retries and total control over the concurrency flow.# Example
The example below showns how this lib works. You will need a resolver which is the function that will called recursively by concurrentPromises and the number of concurrent promises that will run (default is 8).
In this case are created 10 promises that are resolved in a different time to simulate an assincronous I/O.
To finish the conrrentPromises caller you should return *null*;```javascript
it('should limit of concurrent requests', () => {
let count = 0;
const resolver = () => {
return new Promise(resolve => {
if(count < 10) {
count++;
return setTimeout(() => {
resolve(true);
}, Math.floor((Math.random() * 1000) + 1));
}
return resolve(null);
});
};const concurrentPromises = new ConcurrentPromises({resolver, concurrency: 3});
return concurrentPromises.begin()
.then(result => {
expect(result.length).to.be.eql(10);
});
});
```