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,12 +30,20 @@ public:
|
||||||
inline
|
inline
|
||||||
~Defer()
|
~Defer()
|
||||||
{
|
{
|
||||||
|
if (m_Func) {
|
||||||
try {
|
try {
|
||||||
m_Func();
|
m_Func();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
// https://stackoverflow.com/questions/130117/throwing-exceptions-out-of-a-destructor
|
// 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…
Reference in New Issue