diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-20 16:53:01 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-20 17:22:25 +0200 |
commit | 398692722bb31e6f07efa2e212d0ec526963c4a0 (patch) | |
tree | 8c3764147ee1f2525f3fa3f6252d57ec413a20b4 /Userland/Libraries/LibWeb/HTML/EventLoop | |
parent | 60d0f041b75b3099bc8437c2f7f80b943667a379 (diff) | |
download | serenity-398692722bb31e6f07efa2e212d0ec526963c4a0.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML/EventLoop')
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
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 <LibCore/EventLoop.h> #include <LibCore/Timer.h> #include <LibJS/Runtime/VM.h> #include <LibWeb/Bindings/MainThreadVM.h> @@ -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<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(); + + // Real spec steps: + // FIXME: 1. Let task be the event loop's currently running task. // FIXME: 2. Let task source be task's source. |