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
commit a362c37c8b
Notes: sideshowbarker 2024-07-17 03:05:16 +09:00
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;
};
}