# lateral

> 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)

Latest version **3.0.5** (published 2014-01-15) · 0 weekly downloads

## Install

```sh
npm install lateral
pnpm add lateral
yarn add lateral
bun add lateral
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.5 |
| Published | 2014-01-15 |
| First published | 2012-04-20 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | * |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | AJ ONeal |
| Maintainers | coolaj86 |
| Keywords | futuresjs, flow-control, async, asynchronous, futures, promises, deferreds, lateral, parallel, synchronize, util, browser |

## Links

- npm: https://www.npmjs.com/package/lateral
- Repository: https://github.com/FuturesJS/lateral
- Issues: https://github.com/FuturesJS/lateral/issues
- npm.io page: https://npm.io/package/lateral

## Dependencies (1)

- [forEachAsync](https://npm.io/package/forEachAsync.md) ~ 3.0

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 3.0.5 (latest) — 2014-01-15
- 3.0.4 — 2014-01-13
- 3.0.3 — 2014-01-13
- 3.0.2 — 2014-01-13
- 3.0.1 — 2014-01-13
- 2.3.0 — 2012-04-20

## README

Lateral
===

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 in batches of 400, 50, and 50 and you want
to know when each batch (and all batches) have finished...  `lateral` is your guy!

Node.js Installation
---

Node.JS (Server):

```bash
npm install lateral
```

Browser Installation
---

You can install from bower:

```bash
bower install lateral
```

Or download the raw file from <https://raw.github.com/FuturesJS/lateral/master/lateral.js>:

```bash
wget https://raw.github.com/FuturesJS/lateral/master/lateral.js
```

Or build with pakmanager:

```bash
pakmanager build lateral
```

Usage
---

```javascript
;(function () {
  'use strict';

  var Lateral = window.Lateral || require('lateral').Lateral
    , maxCallsAtOnce = 4 // default
    , lateral
    ;

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

  lateral = Lateral.create(onEach, maxCallsAtOnce);

  lateral.add(['a', 'b', 'c', 'd']).then(function () {
    console.log('first batch done');
  });
  lateral.add(['d', 'e', 'f', 'g']).then(function () {
    console.log('second batch done');
  });
  
  lateral.then(function () {
    console.log('did all the things');
  });
}());
```
    
API
---

  * `lateral = Lateral.create(fn, n)`
    * create a Lateral that will execute `fn` on each item to do at most `n` things at once
  * `lateral.add(arr).then(cb)` - adds `arr` to be handled by `fn` and `cb` is called when all in `arr` are handled
  * `lateral.then(callback)` 
    * Fires `callback` when all items in added arrays have been handled

TODO
---

The code is a little hairy and could use some cleaning.

---
_Source: https://npm.io/package/lateral · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
