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