From 9a370a5eedd0fe53d01b8fdf19f69de98630a312 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 4 Apr 2023 09:06:10 -0400 Subject: [PATCH] LibWeb: Support taking matching tasks out of a task queue This will be needed for HTMLMediaElement. --- .../LibWeb/HTML/EventLoop/TaskQueue.cpp | 18 ++++++++++++++++++ .../LibWeb/HTML/EventLoop/TaskQueue.h | 1 + 2 files changed, 19 insertions(+) diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/TaskQueue.cpp b/Userland/Libraries/LibWeb/HTML/EventLoop/TaskQueue.cpp index a8c8a51905d..dcfa458baf1 100644 --- a/Userland/Libraries/LibWeb/HTML/EventLoop/TaskQueue.cpp +++ b/Userland/Libraries/LibWeb/HTML/EventLoop/TaskQueue.cpp @@ -53,4 +53,22 @@ void TaskQueue::remove_tasks_matching(Function filter) }); } +ErrorOr>> TaskQueue::take_tasks_matching(Function filter) +{ + Vector> matching_tasks; + + for (size_t i = 0; i < m_tasks.size();) { + auto& task = m_tasks.at(i); + + if (filter(*task)) { + TRY(matching_tasks.try_append(move(task))); + m_tasks.remove(i); + } else { + ++i; + } + } + + return matching_tasks; +} + } diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/TaskQueue.h b/Userland/Libraries/LibWeb/HTML/EventLoop/TaskQueue.h index f3e31c4facb..59454efa5af 100644 --- a/Userland/Libraries/LibWeb/HTML/EventLoop/TaskQueue.h +++ b/Userland/Libraries/LibWeb/HTML/EventLoop/TaskQueue.h @@ -32,6 +32,7 @@ public: } void remove_tasks_matching(Function); + ErrorOr>> take_tasks_matching(Function); private: HTML::EventLoop& m_event_loop;