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