ladybird/Userland/Libraries/LibWeb/HTML/EventLoop/TaskQueue.h
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

30 lines
571 B
C++

/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Queue.h>
#include <LibWeb/HTML/EventLoop/Task.h>
namespace Web::HTML {
class TaskQueue {
public:
explicit TaskQueue(HTML::EventLoop&);
~TaskQueue();
bool is_empty() const { return m_tasks.is_empty(); }
void add(NonnullOwnPtr<HTML::Task>);
OwnPtr<HTML::Task> take_first_runnable() { return m_tasks.dequeue(); }
private:
HTML::EventLoop& m_event_loop;
Queue<NonnullOwnPtr<HTML::Task>> m_tasks;
};
}