You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 95622a4
Browse filesBrowse the repository at this point in the historyBrowse files
// Calls `callback` when `signal` aborts, and returns a function that stops it. The tasks that share a signal share one listener on it, because Node.js searches all the listeners of a signal to add or remove one, so a listener for each task takes O(n²) time with many tasks.
// Task is now running, so remove the queued-state abort listener
609
-
cleanupQueueAbortHandler();
646
+
waitingTask.stopListeningForAbort?.();
610
647
this.#waitingTasks.delete(waitingTask);
611
648
612
649
// The signal aborted while the task waited, but its abort listener did not run yet, for example because another listener of the signal started the queue. Like an abort while waiting, the task does not start.
// Listen before the task starts, so that an abort while the task starts is not missed, and so that the abort comes before the abort listeners of the task. The abort is first in the race, so it also wins when both are already settled.
// Removing the first item is O(1). Aborting many tasks with one signal removes them in the order they were added, which is the queue order when they have the same priority, and a splice for each would be O(n²).
113
+
if(index===this.#head){
114
+
this.#removeFirst();
115
+
}elseif(index!==-1){
85
116
this.#queue.splice(index,1);
86
117
}
87
118
}
88
119
89
120
dequeue(): RunFunction|undefined{
90
-
if(this.#head ===this.#queue.length){
91
-
returnundefined;
92
-
}
93
-
94
-
constitem=this.#queue[this.#head]!;
95
-
// Drop the reference, so that the function of the task and what it holds can be garbage collected before compaction.
96
-
this.#queue[this.#head]=undefined;
97
-
this.#head++;
98
-
99
-
if(this.#head ===this.#queue.length){
100
-
// Fully drained queues are reset immediately so the next enqueue starts from a clean array.
0 commit comments