1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 13:35:09 +00:00

LibWeb: Support taking matching tasks out of a task queue

This will be needed for HTMLMediaElement.
This commit is contained in:
Timothy Flynn 2023-04-04 09:06:10 -04:00 committed by Linus Groh
parent 807891c0df
commit 9a370a5eed
2 changed files with 19 additions and 0 deletions

View file

@ -53,4 +53,22 @@ void TaskQueue::remove_tasks_matching(Function<bool(HTML::Task const&)> filter)
});
}
ErrorOr<Vector<NonnullOwnPtr<Task>>> TaskQueue::take_tasks_matching(Function<bool(HTML::Task const&)> filter)
{
Vector<NonnullOwnPtr<Task>> 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;
}
}