mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-22 02:26:11 +00:00
![Andreas Kling](/assets/img/avatar_default.png)
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.
25 lines
285 B
C++
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;
|