mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-23 01:12:45 +00:00
LibWeb: Add "parallel queue" and allow it as fetch task destination
Note that it's not actually executing tasks in parallel, it's still throwing them on the HTML event loop task queue, each with its own unique task source. This makes our fetch implementation a lot more robust when HTTP caching is enabled, and you can now click links on https://terminal.shop/ without hitting TODO assertions in fetch.
This commit is contained in:
parent
9a5ef95022
commit
03256a2543
Notes:
github-actions[bot]
2025-07-16 22:14:47 +00:00
Author: https://github.com/awesomekling
Commit: 03256a2543
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5471
10 changed files with 65 additions and 44 deletions
|
@ -4,6 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/FetchController.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/Task.h>
|
||||
#include <LibWeb/HTML/EventLoop/EventLoop.h>
|
||||
|
@ -11,21 +12,25 @@
|
|||
namespace Web::Fetch::Infrastructure {
|
||||
|
||||
// https://fetch.spec.whatwg.org/#queue-a-fetch-task
|
||||
HTML::TaskID queue_fetch_task(JS::Object& task_destination, GC::Ref<GC::Function<void()>> algorithm)
|
||||
HTML::TaskID queue_fetch_task(TaskDestination task_destination, GC::Ref<GC::Function<void()>> algorithm)
|
||||
{
|
||||
// FIXME: 1. If taskDestination is a parallel queue, then enqueue algorithm to taskDestination.
|
||||
VERIFY(!task_destination.has<Empty>());
|
||||
|
||||
// 1. If taskDestination is a parallel queue, then enqueue algorithm to taskDestination.
|
||||
if (auto* parallel_queue = task_destination.get_pointer<NonnullRefPtr<HTML::ParallelQueue>>())
|
||||
return (*parallel_queue)->enqueue(algorithm);
|
||||
|
||||
// 2. Otherwise, queue a global task on the networking task source with taskDestination and algorithm.
|
||||
return HTML::queue_global_task(HTML::Task::Source::Networking, task_destination, algorithm);
|
||||
return HTML::queue_global_task(HTML::Task::Source::Networking, task_destination.get<GC::Ref<JS::Object>>(), algorithm);
|
||||
}
|
||||
|
||||
// AD-HOC: This overload allows tracking the queued task within the fetch controller so that we may cancel queued tasks
|
||||
// when the spec indicates that we must stop an ongoing fetch.
|
||||
HTML::TaskID queue_fetch_task(GC::Ref<FetchController> fetch_controller, JS::Object& task_destination, GC::Ref<GC::Function<void()>> algorithm)
|
||||
HTML::TaskID queue_fetch_task(GC::Ref<FetchController> fetch_controller, TaskDestination task_destination, GC::Ref<GC::Function<void()>> algorithm)
|
||||
{
|
||||
auto fetch_task_id = fetch_controller->next_fetch_task_id();
|
||||
|
||||
auto& heap = task_destination.heap();
|
||||
auto& heap = fetch_controller->heap();
|
||||
auto html_task_id = queue_fetch_task(task_destination, GC::create_function(heap, [fetch_controller, fetch_task_id, algorithm]() {
|
||||
fetch_controller->fetch_task_complete(fetch_task_id);
|
||||
algorithm->function()();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue