diff options
| author | bunnei <bunneidev@gmail.com> | 2020-03-31 15:16:07 -0400 |
|---|---|---|
| committer | bunnei <bunneidev@gmail.com> | 2020-04-17 00:59:28 -0400 |
| commit | b2b0f85b7dc2ab04f1bafeec0992aa34a4313467 (patch) | |
| tree | b3341228156641d7e3f9d0aed5b4ab3ff1e8eb07 /src/common/scope_exit.h | |
| parent | 5b9e69e7fe4eb5533bf3df1282b6fc0675c00a0e (diff) | |
common: scope_exit: Implement mechanism for canceling a scope exit.
Diffstat (limited to 'src/common/scope_exit.h')
| -rw-r--r-- | src/common/scope_exit.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/common/scope_exit.h b/src/common/scope_exit.h index 1176a72b19..68ef5f197e 100644 --- a/src/common/scope_exit.h +++ b/src/common/scope_exit.h @@ -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> |
