mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2025-07-21 09:55:45 +00:00
common: scope_exit: Implement mechanism for canceling a scope exit.
This commit is contained in:
parent
5b9e69e7fe
commit
b2b0f85b7d
1 changed files with 8 additions and 1 deletions
|
@ -12,10 +12,17 @@ template <typename Func>
|
|||
struct ScopeExitHelper {
|
||||
explicit ScopeExitHelper(Func&& func) : func(std::move(func)) {}
|
||||
~ScopeExitHelper() {
|
||||
func();
|
||||
if (active) {
|
||||
func();
|
||||
}
|
||||
}
|
||||
|
||||
void Cancel() {
|
||||
active = false;
|
||||
}
|
||||
|
||||
Func func;
|
||||
bool active{true};
|
||||
};
|
||||
|
||||
template <typename Func>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue