summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/scope_guard.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/scope_guard.h b/src/scope_guard.h
index 37b963ad..d422528c 100644
--- a/src/scope_guard.h
+++ b/src/scope_guard.h
@@ -61,11 +61,19 @@ public:
~ScopeGuard()
{
- _function();
+ if (!_cancelled) {
+ _function();
+ }
+ }
+
+ void cancel()
+ {
+ _cancelled = true;
}
private:
std::function<void()> _function;
+ bool _cancelled = false;
};