mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
docs(docs-infra): avoid persistent AbortSignal listener in wait debounce in search
Cleans up the abort listener once the timeout resolves to prevent it from
remaining attached longer than necessary.
(cherry picked from commit 94b707957a)
This commit is contained in:
committed by
Jessica Janiuk
parent
24b0920755
commit
7b396e8bb2
@@ -228,16 +228,19 @@ function matched(snippet: SnippetResult | undefined): boolean {
|
||||
*/
|
||||
function wait(ms: number, signal: AbortSignal): Promise<void> {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const timeout = setTimeout(() => resolve(), ms);
|
||||
let timeout: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
signal.addEventListener(
|
||||
'abort',
|
||||
() => {
|
||||
clearTimeout(timeout);
|
||||
reject(new Error('Operation aborted'));
|
||||
},
|
||||
{once: true},
|
||||
);
|
||||
const onAbort = () => {
|
||||
clearTimeout(timeout);
|
||||
reject(new Error('Operation aborted'));
|
||||
};
|
||||
|
||||
timeout = setTimeout(() => {
|
||||
signal.removeEventListener('abort', onAbort);
|
||||
resolve();
|
||||
}, ms);
|
||||
|
||||
signal.addEventListener('abort', onAbort, {once: true});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user