Skip to content

Commit

Permalink
extra logging, early return for Package.EnsureCreatedAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsequitur committed Apr 5, 2024
1 parent af05eb5 commit 0e8a80b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ private static async Task<IDisposable> TryCreateAsync(FileInfo lockFile)
throw new ArgumentNullException(nameof(lockFile));
}

const int waitAmount = 100;
var attemptCount = 1;

while (attemptCount <= 100)
Expand All @@ -54,7 +53,7 @@ private static async Task<IDisposable> TryCreateAsync(FileInfo lockFile)
{
}

await Task.Delay(waitAmount);
await Task.Delay(TimeSpan.FromMilliseconds(100));
attemptCount++;

if (attemptCount % 10 == 0)
Expand All @@ -63,6 +62,6 @@ private static async Task<IDisposable> TryCreateAsync(FileInfo lockFile)
}
}

throw new IOException($"Cannot acquire file lock {lockFile.FullName}");
throw new IOException($"Cannot acquire file lock {lockFile.FullName} after {attemptCount} attempts.");
}
}
12 changes: 8 additions & 4 deletions src/Microsoft.DotNet.Interactive.CSharpProject/Build/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using static Microsoft.DotNet.Interactive.CSharpProject.RoslynWorkspaceUtilities.RoslynWorkspaceUtilities;
Expand Down Expand Up @@ -263,8 +262,7 @@ private void InitializeBuildChannel()

private async Task ProcessBuildRequest()
{
await EnsureCreatedAsync();
await EnsureBuiltAsync();
await EnsureReadyAsync();
var ws = CreateRoslynWorkspace();
SetCompletionSourceResult(_buildCompletionSource, ws, _buildCompletionSourceLock);
}
Expand Down Expand Up @@ -299,12 +297,18 @@ private CodeAnalysis.Workspace CreateRoslynWorkspace()

public async Task EnsureReadyAsync()
{
if (_roslynWorkspace is not null)
{
Log.Info("Workspace already loaded for package {name}.", Name);
return;
}

await EnsureCreatedAsync();

await EnsureBuiltAsync();
}

protected async Task EnsureBuiltAsync([CallerMemberName] string caller = null)
protected async Task EnsureBuiltAsync()
{
using var operation = _log.OnEnterAndConfirmOnExit();

Expand Down

0 comments on commit 0e8a80b

Please sign in to comment.