mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-29 11:00:29 +00:00
ef553a4b76
There's no point in busy-waiting for the condition to come true. By passing the `WaitForMoreEvents` flag to `processEvents()`, we allow Qt to block until it has something for us to react to. This was extremely noticeable when waiting for large resources to finish loading.
45 lines
1,007 B
C++
45 lines
1,007 B
C++
/*
|
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#define AK_DONT_REPLACE_STD
|
|
|
|
#include "EventLoopPluginQt.h"
|
|
#include "TimerQt.h"
|
|
#include <AK/Function.h>
|
|
#include <AK/NonnullRefPtr.h>
|
|
#include <QCoreApplication>
|
|
#include <QTimer>
|
|
|
|
namespace Ladybird {
|
|
|
|
EventLoopPluginQt::EventLoopPluginQt() = default;
|
|
EventLoopPluginQt::~EventLoopPluginQt() = default;
|
|
|
|
void EventLoopPluginQt::spin_until(Function<bool()> goal_condition)
|
|
{
|
|
while (!goal_condition())
|
|
QCoreApplication::processEvents(QEventLoop::ProcessEventsFlag::AllEvents | QEventLoop::ProcessEventsFlag::WaitForMoreEvents);
|
|
}
|
|
|
|
void EventLoopPluginQt::deferred_invoke(Function<void()> function)
|
|
{
|
|
VERIFY(function);
|
|
QTimer::singleShot(0, [function = move(function)] {
|
|
function();
|
|
});
|
|
}
|
|
|
|
NonnullRefPtr<Web::Platform::Timer> EventLoopPluginQt::create_timer()
|
|
{
|
|
return TimerQt::create();
|
|
}
|
|
|
|
void EventLoopPluginQt::quit()
|
|
{
|
|
QCoreApplication::quit();
|
|
}
|
|
|
|
}
|