Should we add a utility like this to include/ts/util ?
class Throttle
{
public:
Throttle(unsigned secondsBetween = 60);
// Returns true the first time it's called, and if the time since the
last time it returned true is
// more than secondsBetween seconds.
//
bool operator () ();
// Returns the number of times the member operator has been called.
//
unsigned times() const;
};
void Error(...);
void foo(bool zwoop_ate_too_much_sushi)
{
if (zwoop_ate_too_much_sushi) {
static Throttle t;
if (t()) {
Error("Zwoop ate too much sushi %u times, make salmon an
endangered species", t.times());
}
}
}