mirror of https://github.com/Icinga/icinga2.git
Defer: Allow to cancel the callback before going out of scope
This commit is contained in:
parent
d171301b9d
commit
575af4c980
|
@ -30,13 +30,21 @@ public:
|
|||
inline
|
||||
~Defer()
|
||||
{
|
||||
try {
|
||||
m_Func();
|
||||
} catch (...) {
|
||||
// https://stackoverflow.com/questions/130117/throwing-exceptions-out-of-a-destructor
|
||||
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…
Reference in New Issue