@@ -26,6 +26,8 @@ const chmod = util.promisify(fs.chmod);
26
26
27
27
/** The maxmimum number of installation that can be store until they will be removed */
28
28
const maxInstallCount = 5 ;
29
+ /** Maps concurrent requests to install a version of an exe to a single promise */
30
+ const inProgressInstalls = new Map < string , Promise < string > > ( ) ;
29
31
30
32
export interface Config {
31
33
context : vscode . ExtensionContext ;
@@ -50,6 +52,21 @@ export interface Config {
50
52
51
53
/** Returns the path to the executable */
52
54
export async function install ( config : Config , version : semver . SemVer ) : Promise < string > {
55
+ const key = config . exeName + version . raw ;
56
+ const entry = inProgressInstalls . get ( key ) ;
57
+ if ( entry ) {
58
+ return await entry ;
59
+ }
60
+
61
+ const promise = installGuarded ( config , version ) ;
62
+ inProgressInstalls . set ( key , promise ) ;
63
+
64
+ return await promise . finally ( ( ) => {
65
+ inProgressInstalls . delete ( key ) ;
66
+ } ) ;
67
+ }
68
+
69
+ async function installGuarded ( config : Config , version : semver . SemVer ) : Promise < string > {
53
70
const exeName = config . exeName + ( process . platform === "win32" ? ".exe" : "" ) ;
54
71
const subDirName = `${ getZigOSName ( ) } -${ getZigArchName ( ) } -${ version . raw } ` ;
55
72
const exeUri = vscode . Uri . joinPath ( config . context . globalStorageUri , config . exeName , subDirName , exeName ) ;
0 commit comments