https://github.com/tj/co-parallel
Execute thunks in parallel with concurrency support
https://github.com/tj/co-parallel
Last synced: 9 months ago
JSON representation
Execute thunks in parallel with concurrency support
- Host: GitHub
- URL: https://github.com/tj/co-parallel
- Owner: tj
- Created: 2014-01-03T00:46:53.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2016-12-27T10:03:21.000Z (about 9 years ago)
- Last Synced: 2024-04-13T17:21:12.262Z (almost 2 years ago)
- Language: JavaScript
- Size: 213 KB
- Stars: 109
- Watchers: 4
- Forks: 9
- Open Issues: 4
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
# co-parallel
Parallel execution with concurrency support that maintains result ordering.
## Installation
```
$ npm install co-parallel
```
## Example
```js
var parallel = require('co-parallel');
var request = require('co-request');
var co = require('co');
var urls = [
'http://google.com',
'http://yahoo.com',
'http://ign.com',
'http://cloudup.com',
'http://myspace.com',
'http://facebook.com',
'http://segment.io'
];
function *status(url) {
console.log('GET %s', url);
return (yield request(url)).statusCode;
}
co(function *(){
var reqs = urls.map(status);
var res = yield parallel(reqs, 2);
console.log(res);
})();
```
## API
### parallel(thunks, [concurrency])
Execute `thunks` in parallel, with the given
`concurrency` defaulting to 5.
# License
MIT