mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:57:44 +00:00
LibCore: Allow EventLoop to manage and cancel promises
In this context, the promises are considered "jobs", and such jobs depend in some way on the event loop. Therefore, they can be added to the event loop, and the event loop will cancel all of its pending jobs when it ends.
This commit is contained in:
parent
bfd9f681f7
commit
30295bd988
2 changed files with 26 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2022, kleines Filmröllchen <malu.bertsch@gmail.com>
|
||||
* Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org>
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
|
@ -47,6 +47,8 @@ namespace Core {
|
|||
//
|
||||
// EventLoop has one final responsibility: Handling the InspectorServer connection and processing requests to the Object hierarchy.
|
||||
class EventLoop {
|
||||
friend struct EventLoopPusher;
|
||||
|
||||
public:
|
||||
enum class MakeInspectable {
|
||||
No,
|
||||
|
@ -84,6 +86,8 @@ public:
|
|||
void post_event(Object& receiver, NonnullOwnPtr<Event>&&, ShouldWake = ShouldWake::No);
|
||||
void wake_once(Object& receiver, int custom_event_type);
|
||||
|
||||
void add_job(NonnullRefPtr<Promise<NonnullRefPtr<Object>>> job_promise);
|
||||
|
||||
void deferred_invoke(Function<void()> invokee)
|
||||
{
|
||||
auto context = DeferredInvocationContext::construct();
|
||||
|
@ -141,6 +145,7 @@ private:
|
|||
};
|
||||
|
||||
Vector<QueuedEvent, 64> m_queued_events;
|
||||
Vector<NonnullRefPtr<Promise<NonnullRefPtr<Object>>>> m_pending_promises;
|
||||
static pid_t s_pid;
|
||||
|
||||
bool m_exit_requested { false };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue