mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
25 lines
748 B
TypeScript
25 lines
748 B
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
|
|
/**
|
|
* This is like an `AbortController` but will also abort if the parent aborts,
|
|
* but won't make the parent abort if this aborts (single direction)
|
|
*/
|
|
export class WrappedAbortController extends AbortController {
|
|
constructor(parent?: AbortController | undefined) {
|
|
super();
|
|
|
|
parent?.signal.addEventListener("abort", () => {
|
|
this.abort();
|
|
});
|
|
}
|
|
}
|
|
|
|
export function setTimeoutFor(controller: AbortController, timeout: number): void {
|
|
const handle = setTimeout(() => controller.abort(), timeout);
|
|
|
|
controller.signal.addEventListener("abort", () => clearTimeout(handle));
|
|
}
|