Browse Source

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

nce_cpp
bunnei 6 years ago
parent
commit
b2b0f85b7d
  1. 9
      src/common/scope_exit.h

9
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>

Loading…
Cancel
Save