1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +09:00

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.
This commit is contained in:
Andreas Kling 2019-06-07 09:18:21 +02:00
parent 4edc73ad1f
commit 69a6ce90df
Notes: sideshowbarker 2024-07-19 13:42:15 +09:00
2 changed files with 40 additions and 14 deletions

24
AK/ScopeGuard.h Normal file
View file

@ -0,0 +1,24 @@
#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;