ladybird/Userland/Libraries/LibWeb/HTML/EventLoop/TaskQueue.cpp
Andreas Kling 909e522cf7 LibWeb: Schedule HTML::EventLoop processing when there are queued tasks
Since we can't simply give HTML::EventLoop control of the whole program,
we have to integrate with Core::EventLoop.

We do this by having a single-shot 0ms Core::Timer that we start when
a task is added to the queue, and restart after processing the queue and
there are still tasks in the queue.
2021-09-09 02:30:53 +02:00

27 lines
456 B
C++

/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/HTML/EventLoop/EventLoop.h>
#include <LibWeb/HTML/EventLoop/TaskQueue.h>
namespace Web::HTML {
TaskQueue::TaskQueue(HTML::EventLoop& event_loop)
: m_event_loop(event_loop)
{
}
TaskQueue::~TaskQueue()
{
}
void TaskQueue::add(NonnullOwnPtr<Task> task)
{
m_tasks.enqueue(move(task));
m_event_loop.schedule();
}
}