mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
69a6ce90df
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.
24 lines
285 B
C++
24 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;
|