mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-07 16:49:54 +00:00
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:
parent
68a1a78a1a
commit
a362c37c8b
Notes:
sideshowbarker
2024-07-17 03:05:16 +09:00
Author: https://github.com/alimpfard
Commit: a362c37c8b
Pull-request: https://github.com/SerenityOS/serenity/pull/24313
Reviewed-by: https://github.com/Zaggy1024
4 changed files with 34 additions and 3 deletions
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue