https://github.com/tableflip/async-each-series-throttle
Iterate through items in series but throttle iteratee execution
https://github.com/tableflip/async-each-series-throttle
Last synced: about 1 year ago
JSON representation
Iterate through items in series but throttle iteratee execution
- Host: GitHub
- URL: https://github.com/tableflip/async-each-series-throttle
- Owner: tableflip
- License: mit
- Created: 2017-08-17T14:18:07.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-01-23T08:54:02.000Z (over 8 years ago)
- Last Synced: 2025-02-15T12:46:56.408Z (over 1 year ago)
- Language: JavaScript
- Size: 21.5 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# async-each-series-throttle [](https://travis-ci.org/tableflip/async-each-series-throttle) [](https://david-dm.org/tableflip/async-each-series-throttle)
Iterate through items in series but throttle iteratee execution
## Usage
```js
import eachSeriesThrottle from 'async-each-series-throttle'
const items = [0, 1, 2, 3, 4]
// Number in ms to throttle calls to iteratee
const wait = 1000
// Called only once every ~1000ms at maximum
const iteratee = (item, cb) => {
// Do some async work and callback when done
//
// If this takes _more than_ 1000ms then iteratee will be called again
// immediately after cb is called.
//
// If this takes _less than_ 1000ms then iteratee will be called again after
// ~1000ms have elapsed since the last time it was called.
setTimeout(() => cb(null, item + 1), 500)
}
// Optional callback after everything is done
const callback = (err, results) => {
// All done, after ~4000ms or more
// results is [1, 2, 3, 4, 5]
}
eachSeriesThrottle(items, iteratee, wait, callback)
```
## Contribute
Feel free to dive in! [Open an issue](https://github.com/tableflip/mem-storage-area/issues/new) or submit PRs.
## License
[MIT](LICENSE) © Oli Evans and Alan Shaw