# looper

> async loops that never RangeError

Latest version **4.0.0** (published 2017-04-15) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2017-04-15 |
| First published | 2013-07-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/looper) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 19 |
| Author | Dominic Tarr |
| Maintainers | dominictarr |

## Links

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

## Recent versions

- 4.0.0 (latest) — 2017-04-15
- 3.0.0 — 2014-08-19
- 2.0.0 — 2013-07-09
- 1.0.0 — 2013-07-09

## README

# looper

Loop with callbacks but don't RangeError

[![travis](https://travis-ci.org/dominictarr/looper.png?branch=master)
](https://travis-ci.org/dominictarr/looper)

[![testling](http://ci.testling.com/dominictarr/looper.png)
](http://ci.testling.com/dominictarr/looper)

## Synopsis

Normally, if `mightBeAsync` calls it's cb immediately
this would `RangeError`:

``` js
var l = 100000
;(function next () {
  if(--l) mightBeAsync(next)
})
```

`looper` detects that case, and falls back to a `while` loop,
in computer science something like this is called a [trampoline](https://en.wikipedia.org/wiki/Trampoline_(computing))
this module is simpler than other trampoline libraries such as [tail-call](https://github.com/Gozala/js-tail-call)
because it does not preserve arguments. But this is still useful
for looping when  async recursion is sometimes sync.

This is about 10 times faster than using [setImmediate](http://devdocs.io/node~6_lts/timers#timers_setimmediate_callback_args)

## Example

``` js
var looper = require('looper')

var l = 100000
var next = looper(function () {
  if(--l) probablySync(next)
})

next()
```

when you want to stop looping, don't call `next`.
`looper` checks if each callback is sync or not,
so you can even mix sync and async calls!

## License

MIT

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