mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:57:35 +00:00
LibCore+Userland: Implement Core::deferred_invoke
Core::deferred_invoke is a way of executing an action after previously queued events have been processed. It removes the requirement of having/being a Core::Object subclass in order to defer invocation through Core::Object::deferred_invoke. Core::Object::deferred_invoke now delegates to Core::deferred_invoke. The version with the Object& argument is still present but will be removed in the following commits. This commit additionally fixes a new places where the DeferredInvocationEvent was dispatched to the event loop directly, and replaces them with the Core::deferred_invoke equivalent.
This commit is contained in:
parent
ac24842f48
commit
e9121f8b1f
9 changed files with 63 additions and 23 deletions
|
@ -11,9 +11,12 @@
|
|||
#include <AK/HashMap.h>
|
||||
#include <AK/Noncopyable.h>
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/Time.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <LibCore/DeferredInvocationContext.h>
|
||||
#include <LibCore/Event.h>
|
||||
#include <LibCore/Forward.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
|
@ -76,6 +79,12 @@ public:
|
|||
|
||||
static bool has_been_instantiated();
|
||||
|
||||
void deferred_invoke(Function<void()> invokee)
|
||||
{
|
||||
auto context = DeferredInvocationContext::construct();
|
||||
post_event(context, make<Core::DeferredInvocationEvent>(context, move(invokee)));
|
||||
}
|
||||
|
||||
private:
|
||||
void wait_for_event(WaitMode);
|
||||
Optional<Time> get_next_timer_expiration();
|
||||
|
@ -106,4 +115,9 @@ private:
|
|||
NonnullOwnPtr<Private> m_private;
|
||||
};
|
||||
|
||||
inline void deferred_invoke(Function<void()> invokee)
|
||||
{
|
||||
EventLoop::current().deferred_invoke(move(invokee));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue