Przeglądaj źródła

common: scope_exit: Implement mechanism for canceling a scope exit.

bunnei 6 lat temu
rodzic
commit
4df6ef04ac
1 zmienionych plików z 8 dodań i 1 usunięć
  1. 8 1
      src/common/scope_exit.h

+ 8 - 1
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>