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 | 4df6ef04ac5e2169bdba67937a0b301f569949d6 (patch) | |
tree | b3341228156641d7e3f9d0aed5b4ab3ff1e8eb07 /src/common/scope_exit.h | |
parent | 4caff51710a793c6c2c1069ddd6e92185aa731fe (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> |