2022-09-07 15:30:31 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
2022-09-07 15:30:31 -03:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "EventLoopPluginSerenity.h"
|
|
|
|
|
#include <AK/NonnullRefPtr.h>
|
|
|
|
|
#include <LibCore/EventLoop.h>
|
2022-09-21 15:33:57 -03:00
|
|
|
#include <LibWeb/Platform/TimerSerenity.h>
|
2022-09-07 15:30:31 -03:00
|
|
|
|
2022-09-21 15:33:57 -03:00
|
|
|
namespace Web::Platform {
|
2022-09-07 15:30:31 -03:00
|
|
|
|
|
|
|
|
EventLoopPluginSerenity::EventLoopPluginSerenity() = default;
|
|
|
|
|
EventLoopPluginSerenity::~EventLoopPluginSerenity() = default;
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
void EventLoopPluginSerenity::spin_until(GC::Root<GC::Function<bool()>> goal_condition)
|
2022-09-07 15:30:31 -03:00
|
|
|
{
|
2024-10-30 09:06:56 -03:00
|
|
|
Core::EventLoop::current().spin_until([goal_condition = move(goal_condition)]() {
|
2025-04-29 23:21:31 -03:00
|
|
|
if (Core::EventLoop::current().was_exit_requested())
|
|
|
|
|
::exit(0);
|
2024-10-30 09:06:56 -03:00
|
|
|
return goal_condition->function()();
|
|
|
|
|
});
|
2022-09-07 15:30:31 -03:00
|
|
|
}
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
void EventLoopPluginSerenity::deferred_invoke(GC::Root<GC::Function<void()>> function)
|
2022-09-07 15:30:31 -03:00
|
|
|
{
|
2024-10-30 10:39:29 -03:00
|
|
|
Core::deferred_invoke([function = move(function)]() {
|
|
|
|
|
function->function()();
|
|
|
|
|
});
|
2022-09-07 15:30:31 -03:00
|
|
|
}
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ref<Timer> EventLoopPluginSerenity::create_timer(GC::Heap& heap)
|
2022-09-07 15:30:31 -03:00
|
|
|
{
|
2024-10-30 05:37:08 -03:00
|
|
|
return TimerSerenity::create(heap);
|
2022-09-07 15:30:31 -03:00
|
|
|
}
|
|
|
|
|
|
2022-10-08 05:54:52 -03:00
|
|
|
void EventLoopPluginSerenity::quit()
|
|
|
|
|
{
|
|
|
|
|
Core::EventLoop::current().quit(0);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-07 15:30:31 -03:00
|
|
|
}
|