mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:58:11 +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
1 changed files with 14 additions and 0 deletions
|
@ -4,6 +4,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <LibCore/EventLoop.h>
|
||||||
#include <LibCore/Timer.h>
|
#include <LibCore/Timer.h>
|
||||||
#include <LibJS/Runtime/VM.h>
|
#include <LibJS/Runtime/VM.h>
|
||||||
#include <LibWeb/Bindings/MainThreadVM.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
|
// 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([[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: 1. Let task be the event loop's currently running task.
|
||||||
|
|
||||||
// FIXME: 2. Let task source be task's source.
|
// FIXME: 2. Let task source be task's source.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue