mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-11 01:06:01 +03: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.
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;
|