Remove direct dependency on 'abort-controller' package (#7366)

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2023-03-17 12:59:57 -04:00
1 parent d7b2202c1f
commit 37513dee29
12 files changed
+5 -17

No files matched your search

@@ -3,13 +3,15 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { formatDuration } from "@k8slens/utilities";
/**
* Creates an AbortController with an associated timeout
* @param timeout The number of milliseconds before this controller will auto abort
*/
export function withTimeout(timeout: number): AbortController {
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), timeout);
const id = setTimeout(() => controller.abort(`Operation timed out: timeout ${formatDuration(timeout)}`), timeout);
controller.signal.addEventListener("abort", () => clearTimeout(id));