Example #1
0
        public async Task WaitAsync()
        {
            if (NodeLock == null)
            {
                await DotnetLock.WaitAsync();

                _dotNetLockTaken = true;
                return;
            }

            try
            {
                // We want to take the NPM lock first as is going to be the busiest one, and we want other threads to be
                // able to run dotnet new while we are waiting for another thread to finish running NPM.
                await NodeLock.WaitAsync();

                _nodeLockTaken = true;
                await DotnetLock.WaitAsync();

                _dotNetLockTaken = true;
            }
            catch
            {
                if (_nodeLockTaken)
                {
                    NodeLock.Release();
                    _nodeLockTaken = false;
                }
                throw;
            }
        }
Example #2
0
        private async Task <ProcessEx> RestoreAsync(ITestOutputHelper output, string workingDirectory)
        {
            // It's not safe to run multiple NPM installs in parallel
            // https://github.com/npm/npm/issues/2500
            await NodeLock.WaitAsync();

            try
            {
                output.WriteLine($"Restoring NPM packages in '{workingDirectory}' using npm...");
                var result = ProcessEx.RunViaShell(output, workingDirectory, "npm install");
                return(result);
            }
            finally
            {
                NodeLock.Release();
            }
        }
Example #3
0
 public void Release()
 {
     try
     {
         if (_dotNetLockTaken)
         {
             DotnetLock.Release();
             _dotNetLockTaken = false;
         }
     }
     finally
     {
         if (_nodeLockTaken)
         {
             NodeLock.Release();
             _nodeLockTaken = false;
         }
     }
 }