New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

async-co

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-co

Control flow for co with aync.js (v2) signatures

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
decreased by-89.47%
Maintainers
1
Weekly downloads
 
Created
Source

Control flow for ES6 generator (co) with async.js (v2) signatures

Motivation

async-co provide javascript async/await (through ES6 generator & co) equivalent signatures of the excellent async workflow library.

Addition to the async library signatures

Because of the Promise contract (and sane API), it's easy to "throttle" a function that return a Promise (see the "throttle" API, for a way to make an ultra simple http request pooling).

API

async-co/eachLimit(arr, concurrency, *thunk)

Nothing special here

async-co/eachSeries(arr, *thunk)

// = eachLimit concurrency = 1

async-co/each(arr, *thunk)

// = eachLimit concurrency = arr.length

async-co/eachOfLimit (dict, concurrency, *thunk)

Nothing special here neither

async-co/eachOfSeries(dict, *thunk)

// = eachOfLimit concurrency = 1

async-co/eachOf(dict, *thunk)

// = eachOfLimit concurrency = dict.length

const eachLimit    = require('async-co/eachLimit');

co(function *() {

  var stuffs = [1,2,3, 5, 7]

  yield eachLimit(stuffs, 2, function*(id){
      yield dootherStuffs(id);
  });

});

q = async-co/queue(*thunk, concurrency)

Return a QueueObject you can push task into.

yield q.push(task)

Wait for thunk to process task (wait for worker, if needed)

const queue    = require('async-co/queue');
const fetch    = require('node-fetch');

var q = queue(fetch, 1); //let's be nice

co(function *() {
  yield q.push("http://example.com/stuff.json");
});

co(function *() {
  yield q.push("http://example.com/otherstuff.json"); //will wait for stuff to be retrieved
});

async-co/throttle

Throttle any function that return a promise, sugar syntax helper for async-co/queue

const throttle = require('async-co/throttle');
var  fetch     = require('node-fetch');
fetch = throttle(fetch, 1); //make fetch behave nicely

co(function *() {
  yield fetch("http://example.com/stuff.json");
});

co(function *() {
  yield fetch("http://example.com/otherstuff.json"); //will wait for stuff.json to be retrieved
});

TODO

  • Get rich or die tryin'

Credits

  • 131
  • not dependant upon, yet relying on co
  • inspired from the excellent async

Shoutbox, keywords, SEO love

async/await, ES6 generators, co, async-co, promise, Promises, yield, async, queue, map, throttle, "Let's have a beer & talk in Paris"

Keywords

FAQs

Package last updated on 19 Aug 2016

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