mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00: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:
parent
a63f6d0978
commit
a6efb7752d
1 changed files with 12 additions and 9 deletions
|
|
@ -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});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue