summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML/EventLoop/TaskQueue.h
blob: f3e31c4facb13cd6c99aa9e0df3023f9a82f1537 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
 * 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(); }

    bool has_runnable_tasks() const;

    void add(NonnullOwnPtr<HTML::Task>);
    OwnPtr<HTML::Task> take_first_runnable();

    void enqueue(NonnullOwnPtr<HTML::Task> task) { add(move(task)); }
    OwnPtr<HTML::Task> dequeue()
    {
        if (m_tasks.is_empty())
            return {};
        return m_tasks.take_first();
    }

    void remove_tasks_matching(Function<bool(HTML::Task const&)>);

private:
    HTML::EventLoop& m_event_loop;

    Vector<NonnullOwnPtr<HTML::Task>> m_tasks;
};

}