node-modules/p-gather

Name: p-gather

Owner: node_modules

Description: Execute Promise in parallel with concurrency support and gather all the results.

Created: 2018-03-27 07:19:38.0

Updated: 2018-03-27 10:21:49.0

Pushed: 2018-03-27 10:21:51.0

Homepage: null

Size: 8

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

p-gather

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Execute Promise in parallel with concurrency support and gather all the results.

p-gather is similar with co-parallel, but p-gather will gather all the result of these Promise, even those Promise throw error.

Installation
m install p-gather
Example
t gather = require('p-gather');
t thread = gather.thread;

tion sleep(n) {
turn new Promise(resolve => {
setTimeout(resolve, n);
;


index = 0;
c function random() {
t i = index++;
ait sleep(Math.random() * 100);
 (Math.random() > 0.5) {
throw new Error('error');

turn i;


nc =>{
nst ret = await gather(thread(random, 10));
nsole.log(ret);
;

=>


isError: true, error: [Error: error] },
isError: true, error: [Error: error] },
isError: true, error: [Error: error] },
isError: true, error: [Error: error] },
isError: true, error: [Error: error] },
isError: false, value: 5 },
isError: false, value: 6 },
isError: false, value: 7 },
isError: true, error: [Error: error] },
isError: true, error: [Error: error] }

API
gather(Promise, [concurrency])

Execute Promise array in parallel, with the given concurrency defaulting to 5, and gather the result

gather.thread(Function, [concurrency])

Run a function in parallel N times. Function must return a Promise Object.

License

MIT


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.