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:
parent
4edc73ad1f
commit
69a6ce90df
Notes:
sideshowbarker
2024-07-19 13:42:15 +09:00
Author: https://github.com/awesomekling
Commit: 69a6ce90df
2 changed files with 40 additions and 14 deletions
24
AK/ScopeGuard.h
Normal file
24
AK/ScopeGuard.h
Normal 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;
|
Loading…
Add table
Add a link
Reference in a new issue