diff --git a/AK/ScopeGuard.h b/AK/ScopeGuard.h index 99467966638..6cacfd29d6d 100644 --- a/AK/ScopeGuard.h +++ b/AK/ScopeGuard.h @@ -21,6 +21,28 @@ private: Callback m_callback; }; +template +class ArmedScopeGuard { +public: + ArmedScopeGuard(Callback callback) + : m_callback(move(callback)) + { + } + + ~ArmedScopeGuard() + { + if (m_armed) + m_callback(); + } + + void disarm() { m_armed = false; } + +private: + Callback m_callback; + bool m_armed { true }; +}; + } using AK::ScopeGuard; +using AK::ArmedScopeGuard;