ladybird/AK/ScopeGuard.h
Andreas Kling 69a6ce90df AK: Add a ScopeGuard helper that invokes a callback when destroyed.
This is useful when you want to ensure some little thing happens when you
exit a certain scope.

This patch makes use of it in LibC's netdb code to make sure we close the
connection to the LookupServer.
2019-06-07 09:19:15 +02:00

25 lines
285 B
C++

#pragma once
namespace AK {
template<typename Callback>
class ScopeGuard {
public:
ScopeGuard(Callback callback)
: m_callback(move(callback))
{
}
~ScopeGuard()
{
m_callback();
}
private:
Callback m_callback;
};
}
using AK::ScopeGuard;