mirror of
https://github.com/Instadapp/Swap-Aggregator-Subgraph.git
synced 2024-07-29 21:57:12 +00:00
44 lines
808 B
Markdown
44 lines
808 B
Markdown
# looper
|
|
|
|
Loop with callbacks but don't RangeError
|
|
|
|
[
|
|
](https://travis-ci.org/dominictarr/looper)
|
|
|
|
[
|
|
](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,
|
|
|
|
## Example
|
|
|
|
``` js
|
|
var loop = require('looper')
|
|
|
|
var l = 100000
|
|
loop(function () {
|
|
var next = this
|
|
if(--l) probablySync(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
|