mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
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.
This commit is contained in:
parent
60d0f041b7
commit
398692722b
Notes:
sideshowbarker
2024-07-18 03:36:36 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/398692722bb
1 changed files with 14 additions and 0 deletions
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue