From b2b0f85b7dc2ab04f1bafeec0992aa34a4313467 Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 31 Mar 2020 15:16:07 -0400 Subject: [PATCH] common: scope_exit: Implement mechanism for canceling a scope exit. --- src/common/scope_exit.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 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