1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:14:58 +00:00

Userland: Rename Core::Object to Core::EventReceiver

This is a more precise description of what this class actually does.
This commit is contained in:
Andreas Kling 2023-08-06 18:09:39 +02:00 committed by Jelle Raaijmakers
parent bdf696e488
commit ddbe6bd7b4
128 changed files with 399 additions and 401 deletions

View file

@ -14,7 +14,7 @@
#include <AK/Queue.h>
#include <LibCore/Event.h>
#include <LibCore/EventLoop.h>
#include <LibCore/Object.h>
#include <LibCore/EventReceiver.h>
#include <LibCore/Promise.h>
#include <LibThreading/Thread.h>
@ -35,14 +35,14 @@ private:
};
template<typename Result>
class BackgroundAction final : public Core::Object
class BackgroundAction final : public Core::EventReceiver
, private BackgroundActionBase {
C_OBJECT(BackgroundAction);
public:
// Promise is an implementation detail of BackgroundAction in order to communicate with EventLoop.
// All of the promise's callbacks and state are either managed by us or by EventLoop.
using Promise = Core::Promise<NonnullRefPtr<Core::Object>>;
using Promise = Core::Promise<NonnullRefPtr<Core::EventReceiver>>;
virtual ~BackgroundAction() = default;
@ -55,13 +55,13 @@ public:
private:
BackgroundAction(Function<ErrorOr<Result>(BackgroundAction&)> action, Function<ErrorOr<void>(Result)> on_complete, Optional<Function<void(Error)>> on_error = {})
: Core::Object(&background_thread())
: Core::EventReceiver(&background_thread())
, m_promise(Promise::try_create().release_value_but_fixme_should_propagate_errors())
, m_action(move(action))
, m_on_complete(move(on_complete))
{
if (m_on_complete) {
m_promise->on_resolution = [](NonnullRefPtr<Core::Object>& object) -> ErrorOr<void> {
m_promise->on_resolution = [](NonnullRefPtr<Core::EventReceiver>& object) -> ErrorOr<void> {
auto self = static_ptr_cast<BackgroundAction<Result>>(object);
VERIFY(self->m_result.has_value());
if (auto maybe_error = self->m_on_complete(self->m_result.value()); maybe_error.is_error())

View file

@ -12,7 +12,7 @@
namespace Threading {
Thread::Thread(Function<intptr_t()> action, StringView thread_name)
: Core::Object(nullptr)
: Core::EventReceiver(nullptr)
, m_action(move(action))
, m_thread_name(thread_name.is_null() ? ""sv : thread_name)
{

View file

@ -12,7 +12,7 @@
#include <AK/DistinctNumeric.h>
#include <AK/Function.h>
#include <AK/Result.h>
#include <LibCore/Object.h>
#include <LibCore/EventReceiver.h>
#include <pthread.h>
namespace Threading {
@ -41,7 +41,7 @@ enum class ThreadState : u8 {
Joined,
};
class Thread final : public Core::Object {
class Thread final : public Core::EventReceiver {
C_OBJECT(Thread);
public: