Skip to content

Like forEachAsync and Join had a baby: sequences out n batches of async functions rather than all at once. Part of FuturesJS (Browser, Node.js, Bower, Pakmanager)

License

Notifications You must be signed in to change notification settings

FuturesJS/forAllAsync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

forAllAsync

Basically a forEachAsync that allows n async calls at once.

Another way to think of it is as a thread pool for JavaScript.

Say you have 500 http requests that you want to get done 10 at a time and then know when they've all finished... then forAllAsync is your guy!

Installation

Node.JS (Server):

npm install forallasync

Browser Installation

You can install from bower:

bower install forAllAsync

Or download the raw file from https://raw.github.com/FuturesJS/forAllAsync/master/forAllAsync.js:

wget https://raw.github.com/FuturesJS/forAllAsync/master/forAllAsync.js

Or build with pakmanager:

pakmanager build forAllAsync

Usage

;(function (exports) {
  'use strict';

  var forAllAsync = exports.forAllAsync || require('forallasync').forAllAsync
    , maxCallsAtOnce = 4 // default
    , arr
    ;

  function onEach(complete, item, i) {
    setTimeout(function () {
      console.log(item);
      complete();
    }, 500);
  }

  arr = ['a', 'b', 'c', 'd'];
  forAllAsync(arr, onEach, maxCallsAtOnce).then(function () {
    console.log('did all the things');
  });
}('undefined' !== typeof exports && exports || new Function('return this')())));

API

  • forAllAsync(array, iterator, n).then(callback)
    • execute iterator for each element in array, n at a time and call callback when all are complete

About

Like forEachAsync and Join had a baby: sequences out n batches of async functions rather than all at once. Part of FuturesJS (Browser, Node.js, Bower, Pakmanager)

Resources

License

Stars

Watchers

Forks

Packages

No packages published