1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

add lock around lensViews in initView

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-02-18 09:38:10 -05:00
parent 9563ead2e6
commit 5a36494bc3

View File

@ -2,6 +2,7 @@ import { observable, when } from "mobx";
import { ClusterId, ClusterStore, getClusterFrameUrl } from "../../../common/cluster-store";
import { getMatchedClusterId } from "../../navigation";
import logger from "../../../main/logger";
import AwaitLock from "await-lock";
export interface LensView {
isLoaded?: boolean
@ -10,21 +11,20 @@ export interface LensView {
}
export const lensViews = observable.map<ClusterId, LensView>();
const lensViewsLock = new AwaitLock();
export function hasLoadedView(clusterId: ClusterId): boolean {
return !!lensViews.get(clusterId)?.isLoaded;
}
export async function initView(clusterId: ClusterId) {
await lensViewsLock.acquireAsync();
if (!clusterId || lensViews.has(clusterId)) {
return;
}
const cluster = ClusterStore.getInstance().getById(clusterId);
if (!cluster) {
return;
}
logger.info(`[LENS-VIEW]: init dashboard, clusterId=${clusterId}`);
const parentElem = document.getElementById("lens-views");
const iframe = document.createElement("iframe");
@ -39,6 +39,7 @@ export async function initView(clusterId: ClusterId) {
parentElem.appendChild(iframe);
logger.info(`[LENS-VIEW]: waiting cluster to be ready, clusterId=${clusterId}`);
await cluster.whenReady;
lensViewsLock.release();
await autoCleanOnRemove(clusterId, iframe);
}