Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

co-gather

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

co-gather

Execute thunks in parallel with concurrency support and gather all the results

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10K
decreased by-57.31%
Maintainers
1
Weekly downloads
 
Created
Source

co-gather

Execute thunks, generators, async functions in parallel with concurrency support and gather all the results.

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

Installation

$ npm install co-gather

Example

const gather = require('./');
const sleep = require('mz-modules/sleep');

function* gfun(result, error, interval) {
  yield sleep(interval || 100);
  if (error) throw new Error(error);
  return result;
}

async function afun(result, error, interval) {
  await sleep(interval || 100);
  if (error) throw new Error(error);
  return result;
}

console.time('gather');
gather([
  gfun(1),
  gfun(null, 'error'),
  async () => afun(null, 'error'),
  () => afun(4),
], 2).then(res => {
  console.timeEnd('gather');
  console.log(res);
});

=>

[
  { isError: false, value: 1 },
  { isError: true, error: [Error: error] },
  { isError: true, error: [Error: error] },
  { isError: false, value: 4 }
]

API

gather(items, [concurrency])

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

License

MIT

Keywords

FAQs

Package last updated on 11 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc