Use abort-controller package to fix typing issues (#6077)

This commit is contained in:
Sebastian Malton committed 2022-08-26 11:05:04 -04:00
1 parent 308c106d76
commit 92bca6214f
7 files changed
+22 -11

No files matched your search

@@ -15,6 +15,7 @@ import { DeploymentApi, Ingress, IngressApi, Pod, PodApi } from "../endpoints";
import { getDiForUnitTesting } from "../../../renderer/getDiForUnitTesting";
import apiManagerInjectable from "../api-manager/manager.injectable";
import autoRegistrationInjectable from "../api-manager/auto-registration.injectable";
import { AbortController } from "abort-controller";
jest.mock("../api-manager");
+1 -1
View File
@@ -19,7 +19,6 @@ import { KubeJsonApi } from "./kube-json-api";
import type { Disposer } from "../utils";
import { isDefined, noop, WrappedAbortController } from "../utils";
import type { RequestInit } from "node-fetch";
import type AbortController from "abort-controller";
import type { AgentOptions } from "https";
import { Agent } from "https";
import type { Patch } from "rfc6902";
@@ -28,6 +27,7 @@ import type { PartialDeep } from "type-fest";
import logger from "../logger";
import { Environments, getEnvironmentSpecificLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
import autoRegistrationEmitterInjectable from "./api-manager/auto-registration-emitter.injectable";
import type AbortController from "abort-controller";
/**
* The options used for creating a `KubeApi`
+3 -2
View File
@@ -15,12 +15,12 @@ import { ItemStore } from "../item.store";
import type { KubeApiQueryParams, KubeApi, KubeApiWatchCallback } from "./kube-api";
import { parseKubeApi } from "./kube-api-parse";
import type { RequestInit } from "node-fetch";
import AbortController from "abort-controller";
import type { Patch } from "rfc6902";
import logger from "../logger";
import assert from "assert";
import type { PartialDeep } from "type-fest";
import { entries } from "../utils/objects";
import { AbortController } from "abort-controller";
export type OnLoadFailure = (error: unknown) => void;
@@ -477,7 +477,8 @@ export abstract class KubeObjectStore<
callback,
});
const { signal } = abortController;
// TODO: upgrade node-fetch once we are starting to use ES modules
const signal = abortController.signal;
const callback: KubeApiWatchCallback<D> = (data, error) => {
if (!this.isLoaded || error?.type === "aborted") return;
+6 -1
View File
@@ -2,8 +2,13 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import AbortController from "abort-controller";
import { AbortController } from "abort-controller";
/**
* 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) {
super();
+1 -1
View File
@@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { AbortController } from "abort-controller";
import type AbortController from "abort-controller";
/**
* Return a promise that will be resolved after at least `timeout` ms have
@@ -5,11 +5,15 @@
import { comparer, reaction } from "mobx";
import type { Disposer } from "../../common/utils";
import { disposer, getOrInsert, noop, WrappedAbortController } from "../../common/utils";
import AbortController from "abort-controller";
import { once } from "lodash";
import type { ClusterFrameContext } from "../cluster-frame-context/cluster-frame-context";
import logger from "../../common/logger";
import type { KubeObjectStoreLoadAllParams, KubeObjectStoreSubscribeParams } from "../../common/k8s-api/kube-object.store";
import type { RequestInit } from "node-fetch";
import { AbortController } from "abort-controller";
// TODO: upgrade node-fetch once we are starting to use ES modules
type LegacyAbortSignal = NonNullable<RequestInit["signal"]>;
// Kubernetes watch-api client
// API: https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams