mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 13:45:04 +02:00
Defer: Allow to cancel the callback before going out of scope
This commit is contained in:
parent
aaccd0448f
commit
236a888c1b
@ -30,12 +30,20 @@ public:
|
||||
inline
|
||||
~Defer()
|
||||
{
|
||||
if (m_Func) {
|
||||
try {
|
||||
m_Func();
|
||||
} catch (...) {
|
||||
// https://stackoverflow.com/questions/130117/throwing-exceptions-out-of-a-destructor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
void Cancel()
|
||||
{
|
||||
m_Func = nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
std::function<void()> m_Func;
|
||||
|
Loading…
x
Reference in New Issue
Block a user