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