@@ -4,6 +4,7 @@ import loader from "dialogs/loader";
44
55const managedServers = new Map ( ) ;
66const checkedCommands = new Map ( ) ;
7+ const pendingInstallChecks = new Map ( ) ;
78const announcedServers = new Set ( ) ;
89
910const STATUS_PRESENT = "present" ;
@@ -89,10 +90,29 @@ async function ensureInstalled(server) {
8990 if ( ! launcher ?. checkCommand ) return true ;
9091
9192 const cacheKey = `${ server . id } :${ launcher . checkCommand } ` ;
93+
94+ // Return cached result if already checked
9295 if ( checkedCommands . has ( cacheKey ) ) {
9396 return checkedCommands . get ( cacheKey ) === STATUS_PRESENT ;
9497 }
9598
99+ // If there's already a pending check for this server, wait for it
100+ if ( pendingInstallChecks . has ( cacheKey ) ) {
101+ return pendingInstallChecks . get ( cacheKey ) ;
102+ }
103+
104+ // Create and track the pending promise
105+ const checkPromise = performInstallCheck ( server , launcher , cacheKey ) ;
106+ pendingInstallChecks . set ( cacheKey , checkPromise ) ;
107+
108+ try {
109+ return await checkPromise ;
110+ } finally {
111+ pendingInstallChecks . delete ( cacheKey ) ;
112+ }
113+ }
114+
115+ async function performInstallCheck ( server , launcher , cacheKey ) {
96116 try {
97117 await runCommand ( launcher . checkCommand ) ;
98118 checkedCommands . set ( cacheKey , STATUS_PRESENT ) ;
0 commit comments