From 4df6ef04ac5e2169bdba67937a0b301f569949d6 Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 31 Mar 2020 15:16:07 -0400 Subject: common: scope_exit: Implement mechanism for canceling a scope exit. --- src/common/scope_exit.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/common/scope_exit.h') diff --git a/src/common/scope_exit.h b/src/common/scope_exit.h index 1176a72b1..68ef5f197 100644 --- a/src/common/scope_exit.h +++ b/src/common/scope_exit.h @@ -12,10 +12,17 @@ template 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 -- cgit v1.2.3