mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-03 23:25:20 +00:00
LibWeb: Use Core::EventLoop::spin_until() for the ad-hoc loop spinning
The ideal solution here is to implement a more spec-compliant event loop, but while we get all the pieces in place for that, this at least makes the HTML event loop a bit more responsive since it never has to wait for a 16ms timer to fire.
This commit is contained in:
@@ -45,18 +45,11 @@ EventLoop& main_thread_event_loop()
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#spin-the-event-loop
|
||||
void EventLoop::spin_until([[maybe_unused]] Function<bool()> goal_condition)
|
||||
void EventLoop::spin_until(Function<bool()> goal_condition)
|
||||
{
|
||||
// FIXME: This is an ad-hoc hack until we implement the proper mechanism.
|
||||
if (goal_condition())
|
||||
return;
|
||||
Core::EventLoop loop;
|
||||
auto timer = Core::Timer::create_repeating(16, [&] {
|
||||
if (goal_condition())
|
||||
loop.quit(0);
|
||||
});
|
||||
timer->start();
|
||||
loop.exec();
|
||||
loop.spin_until(move(goal_condition));
|
||||
|
||||
// Real spec steps:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user