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
, this is that, but
for the *NIX command line.
Here's an illustration of what happens when you run—
firehose | zthrottle 1 | expensive
Arrows represent data being written.
Here's a GIF of that:
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:
firehose | zthrottle 1 | expensive
# -> `expensive` gets the most recent `firehose` line, but at 1 Hz
Just put zthrottle
in your $PATH
.
You need zsh
.
Unlicense. Public domain. Use freely.