mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:48:11 +00:00
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.
This commit is contained in:
parent
f2b9ec9f8a
commit
926a49cd81
1 changed files with 2 additions and 9 deletions
|
@ -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<bool()> goal_condition)
|
||||
void EventLoop::spin_until(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();
|
||||
loop.spin_until(move(goal_condition));
|
||||
|
||||
// Real spec steps:
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue