https://github.com/anko/zthrottle
tool to throttle a pipeline, so an expensive consumer gets a line less often
https://github.com/anko/zthrottle
pipeline throttle tool zsh
Last synced: about 1 year ago
JSON representation
tool to throttle a pipeline, so an expensive consumer gets a line less often
- Host: GitHub
- URL: https://github.com/anko/zthrottle
- Owner: anko
- License: unlicense
- Created: 2017-07-15T15:14:45.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-23T21:47:09.000Z (almost 9 years ago)
- Last Synced: 2025-03-30T12:11:26.406Z (about 1 year ago)
- Topics: pipeline, throttle, tool, zsh
- Language: Shell
- Homepage: https://unix.stackexchange.com/q/378334/16404
- Size: 8.79 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# zthrottle
Throttles a pipeline, only letting a line through at most every `$1` seconds.
After each cooldown interval, only the most recent line is printed.
If you've used `lodash.js`' [`_.throttle`][lodash-throttle], this is that, but
for the \*NIX command line.
## Example
Here's an illustration of what happens when you run—
```zsh
firehose | zthrottle 1 | expensive
```
![example of what happens][illustration]
Arrows represent data being written.
Here's a GIF of that:
![the same example as a GIF][gif]
## Why
This is handy for when you have a crazy high rate firehose of data on an input
stream, and a fairly expensive sink that processes them, and you don't want the
sink to get lines too often, but you do want it to get the newest one whenever
it does. So stick `zthrottle` in between:
```zsh
firehose | zthrottle 1 | expensive
# -> `expensive` gets the most recent `firehose` line, but at 1 Hz
```
## Install
Just put `zthrottle` in your `$PATH`.
You need [`zsh`][wiki-zsh].
## License
[Unlicense][unlicense]. Public domain. Use freely.
[gif]: https://user-images.githubusercontent.com/5231746/28240490-f6b818b6-697a-11e7-9923-1d976b542582.gif
[illustration]: https://user-images.githubusercontent.com/5231746/28240427-a0bbf3c0-6979-11e7-9c0c-b597bafd3873.png
[lodash-throttle]: https://lodash.com/docs/4.17.4#throttle
[unlicense]: https://unlicense.org/
[wiki-zsh]: https://en.wikipedia.org/wiki/Z_shell