forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
bfd9f68
commit 30295bd
Showing
2 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* Copyright (c) 2018-2020, Andreas Kling <[email protected]> | ||
* Copyright (c) 2022, kleines Filmröllchen <[email protected]> | ||
* Copyright (c) 2022, kleines Filmröllchen <[email protected]> | ||
* 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 @@ class EventLoop { | |
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 @@ class EventLoop { | |
}; | ||
|
||
Vector<QueuedEvent, 64> m_queued_events; | ||
Vector<NonnullRefPtr<Promise<NonnullRefPtr<Object>>>> m_pending_promises; | ||
static pid_t s_pid; | ||
|
||
bool m_exit_requested { false }; | ||
|