From 926a49cd8195966dd47f6cc8f063dc33836bdfda Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 25 Sep 2021 19:33:13 +0200 Subject: [PATCH] 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. --- .../Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp index 5da9f66f05..b20b58e824 100644 --- a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp +++ b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp @@ -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 goal_condition) +void EventLoop::spin_until(Function 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: