Move util::Deferred into util-types.h

This commit is contained in:
Tim Wojtulewicz 2025-07-10 16:19:36 -07:00
parent e91e9c4523
commit 6e96cb59ec
2 changed files with 12 additions and 12 deletions

View file

@ -62,5 +62,17 @@ private:
void DoFunc(const std::string& path, bool error_aborts = true);
};
/**
* Helper class that runs a function at destruction.
*/
class Deferred {
public:
Deferred(std::function<void()> deferred) : deferred(std::move(deferred)) {}
~Deferred() { deferred(); }
private:
std::function<void()> deferred;
};
} // namespace util
} // namespace zeek