LibCore: Add Core::deferred_invoke_if(F, Condition)

This will invoke the function F only if the provided Condition is met,
otherwise the execution of the function F will be further deferred.
This commit is contained in:
Ali Mohammad Pur
2024-05-08 20:08:18 +02:00
committed by Andreas Kling
parent 68a1a78a1a
commit a362c37c8b
4 changed files with 34 additions and 3 deletions

View File

@@ -13,8 +13,21 @@ namespace Core {
class DeferredInvocationContext final : public Core::EventReceiver {
C_OBJECT(DeferredInvocationContext)
public:
bool should_invoke() const { return m_condition(); }
private:
DeferredInvocationContext() = default;
DeferredInvocationContext()
: m_condition([] { return true; })
{
}
DeferredInvocationContext(Function<bool()> condition)
: m_condition(move(condition))
{
}
Function<bool()> m_condition;
};
}