From 398692722bb31e6f07efa2e212d0ec526963c4a0 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 20 Sep 2021 16:53:01 +0200 Subject: LibWeb: Implement an ad-hoc version of EventLoop::spin_until(condition) This doesn't follow the exact spec steps but instead simply makes a nested Core::EventLoop and spins it while a periodic timer tests the goal condition. --- Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Userland/Libraries/LibWeb/HTML/EventLoop') diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp index a0cd1234fe..556f842ca8 100644 --- a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp +++ b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -46,6 +47,19 @@ 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) { + // 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(); + + // Real spec steps: + // FIXME: 1. Let task be the event loop's currently running task. // FIXME: 2. Let task source be task's source. -- cgit v1.2.3